Best Testkube code snippet using event.init
calendar_test.go
Source:calendar_test.go
...9func TestNewCalendarHaveNoEvents(t *testing.T) {10 inMemory := storage.InMemory{}11 err := inMemory.Init()12 if err != nil {13 t.Error("Can't init storage")14 }15 calendar := Calendar{Storage: &inMemory, Logger: &logrus.Logger{}}16 events, err := calendar.GetAllEvents()17 if err != ErrNoEventsInStorage || len(events) != 0 {18 t.Error("In new storage exist events")19 }20}21func TestAddEventSuccess(t *testing.T) {22 inMemory := storage.InMemory{}23 err := inMemory.Init()24 if err != nil {25 t.Error("Can't init storage")26 }27 calendar := Calendar{Storage: &inMemory, Logger: &logrus.Logger{}}28 event1, _ := event.CreateEvent("2006-01-02T15:00:00+03:00", "2006-01-02T16:00:00+03:00", "Event 1", "Some Desc1")29 err = calendar.AddEvent(event1)30 if err != nil {31 t.Error("Can't add event to storage")32 }33 events, err := calendar.GetAllEvents()34 if err != nil || len(events) != 1 {35 t.Error("In storage not 1 event")36 }37}38func TestDelEventSuccess(t *testing.T) {39 inMemory := storage.InMemory{}40 err := inMemory.Init()41 if err != nil {42 t.Error("Can't init storage")43 }44 calendar := Calendar{Storage: &inMemory, Logger: &logrus.Logger{}}45 event1, _ := event.CreateEvent("2006-01-02T15:00:00+03:00", "2006-01-02T16:00:00+03:00", "Event 1", "Some Desc1")46 _ = calendar.AddEvent(event1)47 err = calendar.DelEvent(1)48 if err != nil {49 t.Error("Can't del event from storage")50 }51 events, err := calendar.GetAllEvents()52 if err == nil || len(events) != 0 {53 t.Error("In storage exist events")54 }55}56func TestAddDateIntervalBusyAtSameTime(t *testing.T) {57 var err error58 inMemory := storage.InMemory{}59 err = inMemory.Init()60 if err != nil {61 t.Error("Can't init storage")62 }63 calendar := Calendar{Storage: &inMemory, Logger: &logrus.Logger{}}64 event1, _ := event.CreateEvent("2006-01-02T15:00:00+03:00", "2006-01-02T16:00:00+03:00", "Event 1", "Some Desc1")65 event2, _ := event.CreateEvent("2006-01-02T15:00:00+03:00", "2006-01-02T16:00:00+03:00", "Event 2", "Some Desc2")66 err = calendar.AddEvent(event1)67 err = calendar.AddEvent(event2)68 if err != ErrDateBusy {69 t.Error("Add not return error for busy interval")70 }71}72func TestAddDateIntervalStartTimeInExistInterval(t *testing.T) {73 var err error74 inMemory := storage.InMemory{}75 err = inMemory.Init()76 if err != nil {77 t.Error("Can't init storage")78 }79 calendar := Calendar{Storage: &inMemory, Logger: &logrus.Logger{}}80 event1, _ := event.CreateEvent("2006-01-02T15:00:00+03:00", "2006-01-02T16:00:00+03:00", "Event 1", "Some Desc1")81 event2, _ := event.CreateEvent("2006-01-02T15:30:00+03:00", "2006-01-02T17:00:00+03:00", "Event 2", "Some Desc2")82 err = calendar.AddEvent(event1)83 err = calendar.AddEvent(event2)84 if err != ErrDateBusy {85 t.Error("Add not return error for busy interval")86 }87}88func TestAddDateIntervalEndTimeInExistInterval(t *testing.T) {89 var err error90 inMemory := storage.InMemory{}91 err = inMemory.Init()92 if err != nil {93 t.Error("Can't init storage")94 }95 calendar := Calendar{Storage: &inMemory, Logger: &logrus.Logger{}}96 event1, _ := event.CreateEvent("2006-01-02T15:00:00+03:00", "2006-01-02T16:00:00+03:00", "Event 1", "Some Desc1")97 event2, _ := event.CreateEvent("2006-01-02T14:00:00+03:00", "2006-01-02T15:30:00+03:00", "Event 2", "Some Desc2")98 err = calendar.AddEvent(event1)99 err = calendar.AddEvent(event2)100 if err != ErrDateBusy {101 t.Error("Add not return error for busy interval")102 }103}104func TestAddDateIntervalInsideExistInterval(t *testing.T) {105 var err error106 inMemory := storage.InMemory{}107 err = inMemory.Init()108 if err != nil {109 t.Error("Can't init storage")110 }111 calendar := Calendar{Storage: &inMemory, Logger: &logrus.Logger{}}112 event1, _ := event.CreateEvent("2006-01-02T15:00:00+03:00", "2006-01-02T16:00:00+03:00", "Event 1", "Some Desc1")113 event2, _ := event.CreateEvent("2006-01-02T15:10:00+03:00", "2006-01-02T15:50:00+03:00", "Event 2", "Some Desc2")114 err = calendar.AddEvent(event1)115 err = calendar.AddEvent(event2)116 if err != ErrDateBusy {117 t.Error("Add not return error for busy interval")118 }119}120func TestAddDateIntervalIncludeExistInterval(t *testing.T) {121 var err error122 inMemory := storage.InMemory{}123 err = inMemory.Init()124 if err != nil {125 t.Error("Can't init storage")126 }127 calendar := Calendar{Storage: &inMemory, Logger: &logrus.Logger{}}128 event1, _ := event.CreateEvent("2006-01-02T15:00:00+03:00", "2006-01-02T16:00:00+03:00", "Event 1", "Some Desc1")129 event2, _ := event.CreateEvent("2006-01-02T14:00:00+03:00", "2006-01-02T17:00:00+03:00", "Event 2", "Some Desc2")130 err = calendar.AddEvent(event1)131 err = calendar.AddEvent(event2)132 if err != ErrDateBusy {133 t.Error("Add not return error for busy interval")134 }135}136func TestAddDateIntervalBusyMultiple(t *testing.T) {137 var err error138 inMemory := storage.InMemory{}139 err = inMemory.Init()140 if err != nil {141 t.Error("Can't init storage")142 }143 calendar := Calendar{Storage: &inMemory, Logger: &logrus.Logger{}}144 event1, _ := event.CreateEvent("2006-01-02T15:00:00+03:00", "2006-01-02T16:00:00+03:00", "Event 1", "Some Desc1")145 event2, _ := event.CreateEvent("2006-01-02T16:00:00+03:00", "2006-01-02T17:00:00+03:00", "Event 2", "Some Desc2")146 event3, _ := event.CreateEvent("2006-01-02T18:00:00+03:00", "2006-01-02T19:00:00+03:00", "Event 3", "Some Desc3")147 err = calendar.AddEvent(event1)148 err = calendar.AddEvent(event2)149 err = calendar.AddEvent(event3)150 if err != nil {151 t.Error("Error on add not intersection events")152 }153 event4, _ := event.CreateEvent("2006-01-02T16:10:00+03:00", "2006-01-02T16:20:00+03:00", "Event 4", "Some Desc4")154 err = calendar.AddEvent(event4)155 if err != ErrDateBusy {156 t.Error("Add not return error for busy interval")157 }158 event5, _ := event.CreateEvent("2006-01-02T10:10:00+03:00", "2006-01-02T22:00:00+03:00", "Event 5", "Some Desc5")159 err = calendar.AddEvent(event5)160 if err != ErrDateBusy {161 t.Error("Add not return error for busy interval")162 }163 event6, _ := event.CreateEvent("2006-01-02T17:10:00+03:00", "2006-01-02T18:10:00+03:00", "Event 6", "Some Desc6")164 err = calendar.AddEvent(event6)165 if err != ErrDateBusy {166 t.Error("Add not return error for busy interval")167 }168}169func TestGetEvent(t *testing.T) {170 inMemory := storage.InMemory{}171 err := inMemory.Init()172 if err != nil {173 t.Error("Can't init storage")174 }175 calendar := Calendar{Storage: &inMemory, Logger: &logrus.Logger{}}176 event1, _ := event.CreateEvent("2006-01-02T15:00:00+03:00", "2006-01-02T16:00:00+03:00", "Event 1", "Some Desc1")177 event1.Id = 1178 _ = calendar.AddEvent(event1)179 _, err = calendar.GetEvent(100)180 if err == nil {181 t.Error("Not get error, for not exist event")182 }183 getEvent, err := calendar.GetEvent(1)184 if err != nil {185 t.Error("Get error, for exist event")186 }187 if getEvent != event1 {188 t.Error("Event in storage not ident")189 }190}191func TestEditEvent(t *testing.T) {192 inMemory := storage.InMemory{}193 err := inMemory.Init()194 if err != nil {195 t.Error("Can't init storage")196 }197 calendar := Calendar{Storage: &inMemory, Logger: &logrus.Logger{}}198 event1, _ := event.CreateEvent("2006-01-02T15:00:00+03:00", "2006-01-02T16:00:00+03:00", "Event 1", "Some Desc1")199 err = calendar.AddEvent(event1)200 if err != nil {201 t.Error("Got not expected error on add event")202 }203 editEvent, _ := calendar.GetEvent(1)204 editEvent.StartTime, _ = time.Parse(time.RFC3339, "2006-01-02T15:10:00+03:00")205 editEvent.EndTime, _ = time.Parse(time.RFC3339, "2006-01-02T15:20:00+03:00")206 editEvent.Title = "newTitle"207 editEvent.Description = "newDescription"208 err = calendar.EditEvent(editEvent)209 if err != nil {...
order.go
Source:order.go
...13type orderEvent struct {14 ev *Event15 batch int16 g uint6417 init gState18 next gState19}20type gStatus int21type gState struct {22 seq uint6423 status gStatus24}25const (26 gDead gStatus = iota27 gRunnable28 gRunning29 gWaiting30 unordered = ^uint64(0)31 garbage = ^uint64(0) - 132 noseq = ^uint64(0)33 seqinc = ^uint64(0) - 134)35// order1007 merges a set of per-P event batches into a single, consistent stream.36// The high level idea is as follows. Events within an individual batch are in37// correct order, because they are emitted by a single P. So we need to produce38// a correct interleaving of the batches. To do this we take first unmerged event39// from each batch (frontier). Then choose subset that is "ready" to be merged,40// that is, events for which all dependencies are already merged. Then we choose41// event with the lowest timestamp from the subset, merge it and repeat.42// This approach ensures that we form a consistent stream even if timestamps are43// incorrect (condition observed on some machines).44func order1007(m map[int][]*Event) (events []*Event, err error) {45 pending := 046 var batches []*eventBatch47 for _, v := range m {48 pending += len(v)49 batches = append(batches, &eventBatch{v, false})50 }51 gs := make(map[uint64]gState)52 var frontier []orderEvent53 for ; pending != 0; pending-- {54 for i, b := range batches {55 if b.selected || len(b.events) == 0 {56 continue57 }58 ev := b.events[0]59 g, init, next := stateTransition(ev)60 if !transitionReady(g, gs[g], init) {61 continue62 }63 frontier = append(frontier, orderEvent{ev, i, g, init, next})64 b.events = b.events[1:]65 b.selected = true66 // Get rid of "Local" events, they are intended merely for ordering.67 switch ev.Type {68 case EvGoStartLocal:69 ev.Type = EvGoStart70 case EvGoUnblockLocal:71 ev.Type = EvGoUnblock72 case EvGoSysExitLocal:73 ev.Type = EvGoSysExit74 }75 }76 if len(frontier) == 0 {77 return nil, fmt.Errorf("no consistent ordering of events possible")78 }79 sort.Sort(orderEventList(frontier))80 f := frontier[0]81 frontier[0] = frontier[len(frontier)-1]82 frontier = frontier[:len(frontier)-1]83 events = append(events, f.ev)84 transition(gs, f.g, f.init, f.next)85 if !batches[f.batch].selected {86 panic("frontier batch is not selected")87 }88 batches[f.batch].selected = false89 }90 // At this point we have a consistent stream of events.91 // Make sure time stamps respect the ordering.92 // The tests will skip (not fail) the test case if they see this error.93 if !sort.IsSorted(eventList(events)) {94 return nil, ErrTimeOrder95 }96 // The last part is giving correct timestamps to EvGoSysExit events.97 // The problem with EvGoSysExit is that actual syscall exit timestamp (ev.Args[2])98 // is potentially acquired long before event emission. So far we've used99 // timestamp of event emission (ev.Ts).100 // We could not set ev.Ts = ev.Args[2] earlier, because it would produce101 // seemingly broken timestamps (misplaced event).102 // We also can't simply update the timestamp and resort events, because103 // if timestamps are broken we will misplace the event and later report104 // logically broken trace (instead of reporting broken timestamps).105 lastSysBlock := make(map[uint64]int64)106 for _, ev := range events {107 switch ev.Type {108 case EvGoSysBlock, EvGoInSyscall:109 lastSysBlock[ev.G] = ev.Ts110 case EvGoSysExit:111 ts := int64(ev.Args[2])112 if ts == 0 {113 continue114 }115 block := lastSysBlock[ev.G]116 if block == 0 {117 return nil, fmt.Errorf("stray syscall exit")118 }119 if ts < block {120 return nil, ErrTimeOrder121 }122 ev.Ts = ts123 }124 }125 sort.Stable(eventList(events))126 return127}128// stateTransition returns goroutine state (sequence and status) when the event129// becomes ready for merging (init) and the goroutine state after the event (next).130func stateTransition(ev *Event) (g uint64, init, next gState) {131 switch ev.Type {132 case EvGoCreate:133 g = ev.Args[0]134 init = gState{0, gDead}135 next = gState{1, gRunnable}136 case EvGoWaiting, EvGoInSyscall:137 g = ev.G138 init = gState{1, gRunnable}139 next = gState{2, gWaiting}140 case EvGoStart, EvGoStartLabel:141 g = ev.G142 init = gState{ev.Args[1], gRunnable}143 next = gState{ev.Args[1] + 1, gRunning}144 case EvGoStartLocal:145 // noseq means that this event is ready for merging as soon as146 // frontier reaches it (EvGoStartLocal is emitted on the same P147 // as the corresponding EvGoCreate/EvGoUnblock, and thus the latter148 // is already merged).149 // seqinc is a stub for cases when event increments g sequence,150 // but since we don't know current seq we also don't know next seq.151 g = ev.G152 init = gState{noseq, gRunnable}153 next = gState{seqinc, gRunning}154 case EvGoBlock, EvGoBlockSend, EvGoBlockRecv, EvGoBlockSelect,155 EvGoBlockSync, EvGoBlockCond, EvGoBlockNet, EvGoSleep,156 EvGoSysBlock, EvGoBlockGC:157 g = ev.G158 init = gState{noseq, gRunning}159 next = gState{noseq, gWaiting}160 case EvGoSched, EvGoPreempt:161 g = ev.G162 init = gState{noseq, gRunning}163 next = gState{noseq, gRunnable}164 case EvGoUnblock, EvGoSysExit:165 g = ev.Args[0]166 init = gState{ev.Args[1], gWaiting}167 next = gState{ev.Args[1] + 1, gRunnable}168 case EvGoUnblockLocal, EvGoSysExitLocal:169 g = ev.Args[0]170 init = gState{noseq, gWaiting}171 next = gState{seqinc, gRunnable}172 case EvGCStart:173 g = garbage174 init = gState{ev.Args[0], gDead}175 next = gState{ev.Args[0] + 1, gDead}176 default:177 // no ordering requirements178 g = unordered179 }180 return181}182func transitionReady(g uint64, curr, init gState) bool {183 return g == unordered || (init.seq == noseq || init.seq == curr.seq) && init.status == curr.status184}185func transition(gs map[uint64]gState, g uint64, init, next gState) {186 if g == unordered {187 return188 }189 curr := gs[g]190 if !transitionReady(g, curr, init) {191 panic("event sequences are broken")192 }193 switch next.seq {194 case noseq:195 next.seq = curr.seq196 case seqinc:197 next.seq = curr.seq + 1198 }199 gs[g] = next200}201// order1005 merges a set of per-P event batches into a single, consistent stream.202func order1005(m map[int][]*Event) (events []*Event, err error) {203 for _, batch := range m {204 events = append(events, batch...)...
init
Using AI Code Generation
1import (2func main() {3 event.Init()4 fmt.Println(event.Event)5}6import (7func Init() {8 fmt.Println("init method of event class")9}
init
Using AI Code Generation
1func main() {2 e := event.NewEvent()3 e.Init()4 e.Start()5}6func main() {7 e := event.NewEvent()8 e.Start()9}10func main() {11 e := event.NewEvent()12 e.Start()13}14func main() {15 e := event.NewEvent()16 e.Start()17}18func main() {19 e := event.NewEvent()20 e.Start()21}22func main() {23 e := event.NewEvent()24 e.Start()25}26func main() {27 e := event.NewEvent()28 e.Start()29}30func main() {31 e := event.NewEvent()32 e.Start()33}34func main() {35 e := event.NewEvent()36 e.Start()37}38func main() {39 e := event.NewEvent()40 e.Start()41}42func main() {43 e := event.NewEvent()44 e.Start()45}46func main() {47 e := event.NewEvent()48 e.Start()49}50func main() {51 e := event.NewEvent()52 e.Start()53}54func main() {55 e := event.NewEvent()56 e.Start()57}58func main() {59 e := event.NewEvent()60 e.Start()61}
init
Using AI Code Generation
1import "fmt"2func init() {3 fmt.Println("Init method called")4}5func main() {6 fmt.Println("Main method called")7}8import "fmt"9func main() {10 fmt.Println("Main method called")11}12import "fmt"13func init() {14 fmt.Println("Init method called")15}16import "fmt"17func init() {18 fmt.Println("Init method called")19}20func main() {21 fmt.Println("Main method called")22}23import "fmt"24func init() {25 fmt.Println("Init method called")26}27func main() {28 fmt.Println("Main method called")29}30func init() {31 fmt.Println("Init method called again")32}33import "fmt"34func init() {35 fmt.Println("Init method called")36}37func main() {38 fmt.Println("Main method called")39}40func init() {41 fmt.Println("Init method called again")42}43func init() {44 fmt.Println("Init method called again and again")45}46import "fmt"47func init() {48 fmt.Println("Init method called")49}50func main() {51 fmt.Println("Main method called")52}53func init() {54 fmt.Println("Init method called again")55}56func init() {57 fmt.Println("Init method called again and again")58}59func init() {60 fmt.Println("Init method called again and again and again")61}
init
Using AI Code Generation
1import (2func main() {3 gin.SetMode(gin.ReleaseMode)4 router := gin.New()5 router.Use(gin.Logger())6 router.Use(gin.Recovery())7 router.GET("/ping", func(c *gin.Context) {8 c.String(200, "pong")9 })10 lambda.Start(ginadapter.New(router))11}
init
Using AI Code Generation
1import (2type Event struct {3}4func (e *Event) init() {5 e.eventChannel = make(chan string)6 e.wg = &sync.WaitGroup{}7}8func (e *Event) sendEvent(event string) {9 e.wg.Add(1)10}11func (e *Event) receiveEvent() {12 e.wg.Done()13 fmt.Println("Received event", event)14}15func (e *Event) wait() {16 e.wg.Wait()17}18func main() {19 e := Event{}20 e.init()21 e.sendEvent("Event 1")22 e.sendEvent("Event 2")23 e.sendEvent("Event 3")24 e.receiveEvent()25 e.receiveEvent()26 e.receiveEvent()27 e.wait()28 fmt.Println("Number of goroutines", runtime.NumGoroutine())29}
init
Using AI Code Generation
1import "fmt"2func main() {3 fmt.Println("Hello, playground")4 event := libevent.NewEvent()5 event.Add(1)6 event.Add(2)7 event.Add(3)8 event.Add(4)9 event.Add(5)10 event.Remove(3)11 event.Remove(4)12 event.Remove(5)13 event.Remove(1)14 event.Remove(2)15 event.Remove(3)16 event.Remove(4)17 event.Remove(5)18 event.Add(1)19 event.Add(2)20 event.Add(3)21 event.Add(4)22 event.Add(5)23 event.Remove(3)24 event.Remove(4)25 event.Remove(5)26 event.Remove(1)27 event.Remove(2)28 event.Remove(3)29 event.Remove(4)30 event.Remove(5)31 event.Add(1)32 event.Add(2)33 event.Add(3)34 event.Add(4)35 event.Add(5)36 event.Remove(3)37 event.Remove(4)38 event.Remove(5)39 event.Remove(1)40 event.Remove(2)41 event.Remove(3)42 event.Remove(4)43 event.Remove(5)44 event.Add(1)45 event.Add(2)46 event.Add(3)
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!!