Best Syzkaller code snippet using main.cacheUpdate
service.go
Source:service.go
1package service2import (3 "context"4 "runtime"5 "time"6 "go-common/app/service/main/archive/api"7 "go-common/app/service/main/archive/conf"8 arcdao "go-common/app/service/main/archive/dao/archive"9 shareDao "go-common/app/service/main/archive/dao/share"10 shotDao "go-common/app/service/main/archive/dao/videoshot"11 "go-common/app/service/main/archive/model/archive"12 "go-common/library/log"13 "go-common/library/stat/prom"14)15var (16 _emptyArchives3 = make(map[int64]*api.Arc)17)18// Service is service.19type Service struct {20 c *conf.Config21 // dao22 arc *arcdao.Dao23 share *shareDao.Dao24 shot *shotDao.Dao25 // acc rpc26 // acc *accrpc.Service227 // types28 allTypes map[int16]*archive.ArcType29 ridToReid map[int16]int1630 bnjList map[int64]struct{}31 // cache chan32 cacheCh chan func()33 // prom34 hitProm *prom.Prom35 missProm *prom.Prom36}37// New new a Service and return.38func New(c *conf.Config) (s *Service) {39 s = &Service{40 c: c,41 // dao42 arc: arcdao.New(c),43 share: shareDao.New(c),44 shot: shotDao.New(c),45 // acc rpc46 // acc: accrpc.New2(c.AccountRPC),47 // types48 allTypes: make(map[int16]*archive.ArcType),49 ridToReid: make(map[int16]int16),50 // cache chan51 cacheCh: make(chan func(), 1024),52 // prom53 hitProm: prom.CacheHit,54 missProm: prom.CacheMiss,55 bnjList: make(map[int64]struct{}),56 }57 s.loadBnjList()58 s.loadTypes()59 go s.loadproc()60 for i := 0; i < runtime.NumCPU(); i++ {61 go s.cacheproc()62 }63 return64}65// AllTypes return all types66func (s *Service) AllTypes(c context.Context) (types map[int16]*archive.ArcType) {67 types = s.allTypes68 return69}70// CacheUpdate job update/del/add archive cache71func (s *Service) CacheUpdate(c context.Context, aid int64, tp string, oldMid int64) (err error) {72 if err = s.arc.UpArchiveCache(c, aid); err != nil {73 log.Error("s.arc.UpArchiveCache(%d) error(%v)", aid, err)74 }75 if err = s.arc.InitStatCache3(c, aid); err != nil {76 log.Error("s.arc.InitStatCache3(%d) error(%v)", aid, err)77 }78 if oldMid != 0 {79 if err = s.DelUpperPassedCache(c, aid, oldMid); err != nil {80 log.Error("s.DelUpperPassedCache(%d, %d) error(%v)", aid, oldMid)81 }82 }83 switch tp {84 case archive.CacheAdd:85 if err = s.AddUpperPassedCache(c, aid); err != nil {86 log.Error("s.AddUpperPassedCache(%d) error(%v)", aid, err)87 }88 if err = s.AddRegionArc(c, aid); err != nil {89 log.Error("s.AddRegionArc(%d) error(%v)", aid, err)90 }91 case archive.CacheUpdate:92 // NOTE: nothing todo93 case archive.CacheDelete:94 if err = s.DelUpperPassedCache(c, aid, 0); err != nil {95 log.Error("s.DelUpperPassedCache(%d) error(%v)", aid, err)96 }97 if err = s.DelRegionArc(c, aid, 0); err != nil {98 log.Error("s.DelRegionArc(%d) error(%v)", aid, err)99 }100 default:101 // NOTE: nothing todo102 }103 return104}105// FieldCacheUpdate job update field cache106func (s *Service) FieldCacheUpdate(c context.Context, aid int64, oldType, nwType int16) (err error) {107 if nwType != 0 {108 if err = s.AddRegionArc(c, aid); err != nil {109 log.Error("s.AddRegionArc(%d) error(%v)", aid, err)110 }111 }112 if oldType != 0 {113 if err = s.DelRegionArc(c, aid, oldType); err != nil {114 log.Error("s.DelRegionArc(%d,%d) error(%d)", aid, oldType, err)115 }116 }117 return118}119// Ping ping success.120func (s *Service) Ping(c context.Context) (err error) {121 err = s.arc.Ping(c)122 return123}124// Close resource.125func (s *Service) Close() {126 s.arc.Close()127}128func (s *Service) loadBnjList() {129 bnjList := make(map[int64]struct{})130 for _, aid := range s.c.BnjList {131 bnjList[aid] = struct{}{}132 }133 s.bnjList = bnjList134}135func (s *Service) loadTypes() {136 var (137 ridToReid = make(map[int16]int16)138 types map[int16]*archive.ArcType139 err error140 )141 if types, err = s.arc.Types(context.TODO()); err != nil {142 log.Error("s.arc.Types error(%v)", err)143 return144 }145 for _, t := range types {146 if t.Pid != 0 {147 ridToReid[t.ID] = t.Pid148 }149 }150 s.allTypes = types151 s.ridToReid = ridToReid152}153func (s *Service) loadproc() {154 for {155 time.Sleep(time.Duration(s.c.Tick))156 s.loadTypes()157 s.loadBnjList()158 }159}160func (s *Service) addCache(f func()) {161 select {162 case s.cacheCh <- f:163 default:164 log.Warn("s.cacheCh is full")165 }166}167func (s *Service) cacheproc() {168 for {169 f, ok := <-s.cacheCh170 if !ok {171 return172 }173 f()174 }175}...
service_test.go
Source:service_test.go
1package service2import (3 "context"4 "flag"5 "path/filepath"6 "testing"7 "go-common/app/service/main/archive/conf"8 . "github.com/smartystreets/goconvey/convey"9)10var (11 s *Service12)13func init() {14 dir, _ := filepath.Abs("../cmd/archive-service-test.toml")15 flag.Set("conf", dir)16 conf.Init()17 s = New(conf.Conf)18}19func Test_AllTypes(t *testing.T) {20 Convey("AllTypes", t, func() {21 types := s.AllTypes(context.TODO())22 So(types, ShouldNotBeNil)23 })24}25func Test_CacheUpdate(t *testing.T) {26 Convey("CacheUpdate", t, func() {27 err := s.CacheUpdate(context.TODO(), 1, "update", 1)28 So(err, ShouldBeNil)29 })30}31func Test_FieldCacheUpdate(t *testing.T) {32 Convey("FieldCacheUpdate", t, func() {33 err := s.FieldCacheUpdate(context.TODO(), 1, 1, 2)34 So(err, ShouldBeNil)35 })36}37func Test_Ping(t *testing.T) {38 Convey("Ping", t, func() {39 err := s.Ping(context.TODO())40 So(err, ShouldBeNil)41 })42}...
cacheUpdate
Using AI Code Generation
1import (2func main() {3 fmt.Println("main")4 cacheUpdate()5}6import (7func main() {8 fmt.Println("main")9 cacheUpdate()10}11import (12func main() {13 fmt.Println("main")14 cacheUpdate()15}16import (17func main() {18 fmt.Println("main")19 cacheUpdate()20}21import (22func main() {23 fmt.Println("main")24 cacheUpdate()25}26import (27func main() {28 fmt.Println("main")29 cacheUpdate()30}31import (32func main() {33 fmt.Println("main")34 cacheUpdate()35}36import (37func main() {38 fmt.Println("main")39 cacheUpdate()40}41import (42func main() {43 fmt.Println("main")44 cacheUpdate()45}46import (47func main() {48 fmt.Println("main")49 cacheUpdate()50}51import (52func main() {53 fmt.Println("main")54 cacheUpdate()55}56import (57func main() {58 fmt.Println("main")59 cacheUpdate()60}
cacheUpdate
Using AI Code Generation
1import (2func main() {3 cache := New(3)4 cache.Set("a", 1)5 cache.Set("b", 2)6 cache.Set("c", 3)7 fmt.Println(cache)8}9import (10func main() {11 cache := New(3)12 cache.Set("a", 1)13 cache.Set("b", 2)14 cache.Set("c", 3)15 fmt.Println(cache)16 cache.Set("b", 4)17 fmt.Println(cache)18}19import (20func main() {21 cache := New(3)22 cache.Set("a", 1)23 cache.Set("b", 2)24 cache.Set("c", 3)25 fmt.Println(cache)26 cache.Set("b", 4)27 fmt.Println(cache)28 cache.Set("d", 5)29 fmt.Println(cache)30}31import (32func main() {33 cache := New(3)34 cache.Set("a", 1)35 cache.Set("b", 2)36 cache.Set("c", 3)37 fmt.Println(cache)38 cache.Set("b", 4)39 fmt.Println(cache)40 cache.Set("d", 5)41 fmt.Println(cache)42 fmt.Println(cache.Get("b"))43}44import (45func main()
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!