How to use Wait method of mocks Package

Best Syzkaller code snippet using mocks.Wait

scheduler_test.go

Source:scheduler_test.go Github

copy

Full Screen

...51 config := configFixture()52 namespace := core.TagFixture()53 seeder := mocks.newPeer(config)54 leecher := mocks.newPeer(config)55 var wg sync.WaitGroup56 for i := 0; i < 5; i++ {57 blob := core.NewBlobFixture()58 mocks.metaInfoClient.EXPECT().Download(59 namespace, blob.Digest).Return(blob.MetaInfo, nil).Times(2)60 wg.Add(1)61 go func() {62 defer wg.Done()63 seeder.writeTorrent(namespace, blob)64 require.NoError(seeder.scheduler.Download(namespace, blob.Digest))65 require.NoError(leecher.scheduler.Download(namespace, blob.Digest))66 leecher.checkTorrent(t, namespace, blob)67 }()68 }69 wg.Wait()70}71func TestDownloadManyTorrentsWithSeederAndManyLeechers(t *testing.T) {72 require := require.New(t)73 mocks, cleanup := newTestMocks(t)74 defer cleanup()75 config := configFixture()76 namespace := core.TagFixture()77 seeder := mocks.newPeer(config)78 leechers := mocks.newPeers(5, config)79 // Start seeding each torrent.80 blobs := make([]*core.BlobFixture, 5)81 for i := range blobs {82 blob := core.NewBlobFixture()83 blobs[i] = blob84 mocks.metaInfoClient.EXPECT().Download(85 namespace, blob.Digest).Return(blob.MetaInfo, nil).Times(6)86 seeder.writeTorrent(namespace, blob)87 require.NoError(seeder.scheduler.Download(namespace, blob.Digest))88 }89 var wg sync.WaitGroup90 for _, blob := range blobs {91 blob := blob92 for _, p := range leechers {93 p := p94 wg.Add(1)95 go func() {96 defer wg.Done()97 require.NoError(p.scheduler.Download(namespace, blob.Digest))98 p.checkTorrent(t, namespace, blob)99 }()100 }101 }102 wg.Wait()103}104func TestDownloadTorrentWhenPeersAllHaveDifferentPiece(t *testing.T) {105 require := require.New(t)106 mocks, cleanup := newTestMocks(t)107 defer cleanup()108 config := configFixture()109 namespace := core.TagFixture()110 peers := mocks.newPeers(10, config)111 pieceLength := 256112 blob := core.SizedBlobFixture(uint64(len(peers)*pieceLength), uint64(pieceLength))113 mocks.metaInfoClient.EXPECT().Download(114 namespace, blob.Digest).Return(blob.MetaInfo, nil).Times(len(peers))115 var wg sync.WaitGroup116 for i, p := range peers {117 tor, err := p.torrentArchive.CreateTorrent(namespace, blob.Digest)118 require.NoError(err)119 piece := make([]byte, pieceLength)120 start := i * pieceLength121 stop := (i + 1) * pieceLength122 copy(piece, blob.Content[start:stop])123 require.NoError(tor.WritePiece(piecereader.NewBuffer(piece), i))124 p := p125 wg.Add(1)126 go func() {127 defer wg.Done()128 require.NoError(p.scheduler.Download(namespace, blob.Digest))129 p.checkTorrent(t, namespace, blob)130 }()131 }132 wg.Wait()133}134func TestSeederTTI(t *testing.T) {135 require := require.New(t)136 mocks, cleanup := newTestMocks(t)137 defer cleanup()138 config := configFixture()139 blob := core.NewBlobFixture()140 namespace := core.TagFixture()141 mocks.metaInfoClient.EXPECT().Download(142 namespace, blob.Digest).Return(blob.MetaInfo, nil).Times(2)143 clk := clock.NewMock()144 w := newEventWatcher()145 seeder := mocks.newPeer(config, withEventLoop(w), withClock(clk))146 seeder.writeTorrent(namespace, blob)147 require.NoError(seeder.scheduler.Download(namespace, blob.Digest))148 leecher := mocks.newPeer(config, withClock(clk))149 errc := make(chan error)150 go func() { errc <- leecher.scheduler.Download(namespace, blob.Digest) }()151 require.NoError(<-errc)152 leecher.checkTorrent(t, namespace, blob)153 // Conns expire...154 clk.Add(config.ConnTTI)155 clk.Add(config.PreemptionInterval)156 w.waitFor(t, preemptionTickEvent{})157 // Then seeding torrents expire.158 clk.Add(config.SeederTTI)159 waitForTorrentRemoved(t, seeder.scheduler, blob.MetaInfo.InfoHash())160 waitForTorrentRemoved(t, leecher.scheduler, blob.MetaInfo.InfoHash())161 require.False(hasConn(seeder.scheduler, leecher.pctx.PeerID, blob.MetaInfo.InfoHash()))162 require.False(hasConn(leecher.scheduler, seeder.pctx.PeerID, blob.MetaInfo.InfoHash()))163 // Idle seeder should keep around the torrent file so it can still serve content.164 _, err := seeder.torrentArchive.Stat(namespace, blob.Digest)165 require.NoError(err)166}167func TestLeecherTTI(t *testing.T) {168 t.Skip()169 require := require.New(t)170 mocks, cleanup := newTestMocks(t)171 defer cleanup()172 config := configFixture()173 clk := clock.NewMock()174 w := newEventWatcher()175 blob := core.NewBlobFixture()176 namespace := core.TagFixture()177 mocks.metaInfoClient.EXPECT().Download(namespace, blob.Digest).Return(blob.MetaInfo, nil)178 p := mocks.newPeer(config, withEventLoop(w), withClock(clk))179 errc := make(chan error)180 go func() { errc <- p.scheduler.Download(namespace, blob.Digest) }()181 waitForTorrentAdded(t, p.scheduler, blob.MetaInfo.InfoHash())182 clk.Add(config.LeecherTTI)183 w.waitFor(t, preemptionTickEvent{})184 require.Equal(ErrTorrentTimeout, <-errc)185 // Idle leecher should delete torrent file to prevent it from being revived.186 _, err := p.torrentArchive.Stat(namespace, blob.Digest)187 require.True(os.IsNotExist(err))188}189func TestMultipleDownloadsForSameTorrentSucceed(t *testing.T) {190 require := require.New(t)191 mocks, cleanup := newTestMocks(t)192 defer cleanup()193 blob := core.NewBlobFixture()194 namespace := core.TagFixture()195 // Allow any number of downloads due to concurrency below.196 mocks.metaInfoClient.EXPECT().Download(197 namespace, blob.Digest).Return(blob.MetaInfo, nil).AnyTimes()198 config := configFixture()199 seeder := mocks.newPeer(config)200 seeder.writeTorrent(namespace, blob)201 require.NoError(seeder.scheduler.Download(namespace, blob.Digest))202 leecher := mocks.newPeer(config)203 var wg sync.WaitGroup204 for i := 0; i < 10; i++ {205 wg.Add(1)206 go func() {207 defer wg.Done()208 // Multiple goroutines should be able to wait on the same torrent.209 require.NoError(leecher.scheduler.Download(namespace, blob.Digest))210 }()211 }212 wg.Wait()213 leecher.checkTorrent(t, namespace, blob)214 // After the torrent is complete, further calls to Download should succeed immediately.215 require.NoError(leecher.scheduler.Download(namespace, blob.Digest))216}217func TestEmitStatsEventTriggers(t *testing.T) {218 mocks, cleanup := newTestMocks(t)219 defer cleanup()220 config := configFixture()221 clk := clock.NewMock()222 w := newEventWatcher()223 mocks.newPeer(config, withEventLoop(w), withClock(clk))224 clk.Add(config.EmitStatsInterval)225 w.waitFor(t, emitStatsEvent{})226}...

Full Screen

Full Screen

channel.go

Source:channel.go Github

copy

Full Screen

...22 false, // immediate23 amqpOpt,24 )25}26func (ch *Channel) Confirm(noWait bool) error {27 return ch.Channel.Confirm(noWait)28}29func (ch *Channel) NotifyPublish(confirm chan mocks.Confirmation) chan mocks.Confirmation {30 amqpConfirms := ch.Channel.NotifyPublish(make(chan amqp.Confirmation, cap(confirm)))31 go func() {32 for c := range amqpConfirms {33 confirm <- Confirmation{c}34 }35 close(confirm)36 }()37 return confirm38}39func (ch *Channel) Consume(queue, consumer string, opt mocks.Option) (<-chan mocks.Delivery, error) {40 var (41 autoAck, exclusive, noLocal, noWait bool42 args amqp.Table43 )44 if v, ok := opt["autoAck"]; ok {45 autoAck, ok = v.(bool)46 if !ok {47 return nil, errors.New("durable option is of type bool")48 }49 }50 if v, ok := opt["exclusive"]; ok {51 exclusive, ok = v.(bool)52 if !ok {53 return nil, errors.New("exclusive option is of type bool")54 }55 }56 if v, ok := opt["noLocal"]; ok {57 noLocal, ok = v.(bool)58 if !ok {59 return nil, errors.New("noLocal option is of type bool")60 }61 }62 if v, ok := opt["noWait"]; ok {63 noWait, ok = v.(bool)64 if !ok {65 return nil, errors.New("noWait option is of type bool")66 }67 }68 if v, ok := opt["args"]; ok {69 args, ok = v.(amqp.Table)70 if !ok {71 return nil, errors.New("args is of type amqp.Table")72 }73 }74 amqpd, err := ch.Channel.Consume(queue, consumer, autoAck, exclusive, noLocal, noWait, args)75 if err != nil {76 return nil, err77 }78 deliveries := make(chan mocks.Delivery)79 go func() {80 for d := range amqpd {81 delivery := d82 deliveries <- &Delivery{&delivery}83 }84 close(deliveries)85 }()86 return deliveries, nil87}88func (ch *Channel) ExchangeDeclare(name, kind string, opt mocks.Option) error {89 return ch.exchangeDeclare(name, kind, false, opt)90}91func (ch *Channel) ExchangeDeclarePassive(name, kind string, opt mocks.Option) error {92 return ch.exchangeDeclare(name, kind, true, opt)93}94func (ch *Channel) exchangeDeclare(name, kind string, passive bool, opt mocks.Option) error {95 var (96 durable, autoDelete, internal, noWait bool97 args amqp.Table98 )99 if v, ok := opt["durable"]; ok {100 durable, ok = v.(bool)101 if !ok {102 return errors.New("durable option is of type bool")103 }104 }105 if v, ok := opt["autoDelete"]; ok {106 autoDelete, ok = v.(bool)107 if !ok {108 return errors.New("autoDelete option is of type bool")109 }110 }111 if v, ok := opt["internal"]; ok {112 internal, ok = v.(bool)113 if !ok {114 return errors.New("internal option is of type bool")115 }116 }117 if v, ok := opt["noWait"]; ok {118 noWait, ok = v.(bool)119 if !ok {120 return errors.New("noWait option is of type bool")121 }122 }123 if v, ok := opt["args"]; ok {124 args, ok = v.(amqp.Table)125 if !ok {126 return errors.New("args is of type amqp.Table")127 }128 }129 if passive {130 return ch.Channel.ExchangeDeclarePassive(name, kind, durable, autoDelete, internal, noWait, args)131 }132 return ch.Channel.ExchangeDeclare(name, kind, durable, autoDelete, internal, noWait, args)133}134func (ch *Channel) QueueInspect(name string) (mocks.Queue, error) {135 q, err := ch.Channel.QueueInspect(name)136 return &Queue{&q}, err137}138func (ch *Channel) QueueUnbind(name, route, exchange string, _ mocks.Option) error {139 return ch.Channel.QueueUnbind(name, route, exchange, nil)140}141// QueueBind binds the route key to queue142func (ch *Channel) QueueBind(name, key, exchange string, opt mocks.Option) error {143 var (144 noWait bool145 args amqp.Table146 )147 if v, ok := opt["noWait"]; ok {148 noWait, ok = v.(bool)149 if !ok {150 return errors.New("noWait option is of type bool")151 }152 }153 if v, ok := opt["args"]; ok {154 args, ok = v.(amqp.Table)155 if !ok {156 return errors.New("args is of type amqp.Table")157 }158 }159 return ch.Channel.QueueBind(name, key, exchange, noWait, args)160}161// QueueDeclare declares a new AMQP queue162func (ch *Channel) QueueDeclare(name string, opt mocks.Option) (mocks.Queue, error) {163 return ch.queueDeclare(name, false, opt)164}165// QueueDeclarePassive declares an existing AMQP queue166func (ch *Channel) QueueDeclarePassive(name string, opt mocks.Option) (mocks.Queue, error) {167 return ch.queueDeclare(name, true, opt)168}169func (ch *Channel) queueDeclare(name string, passive bool, opt mocks.Option) (mocks.Queue, error) {170 var (171 durable, autoDelete, exclusive, noWait bool172 args amqp.Table173 )174 if v, ok := opt["durable"]; ok {175 durable, ok = v.(bool)176 if !ok {177 return nil, errors.New("durable option is of type bool")178 }179 }180 if v, ok := opt["autoDelete"]; ok {181 autoDelete, ok = v.(bool)182 if !ok {183 return nil, errors.New("autoDelete option is of type bool")184 }185 }186 if v, ok := opt["exclusive"]; ok {187 exclusive, ok = v.(bool)188 if !ok {189 return nil, errors.New("Exclusive option is of type bool")190 }191 }192 if v, ok := opt["noWait"]; ok {193 noWait, ok = v.(bool)194 if !ok {195 return nil, errors.New("noWait option is of type bool")196 }197 }198 if v, ok := opt["args"]; ok {199 args, ok = v.(amqp.Table)200 if !ok {201 return nil, errors.New("args is of type amqp.Table")202 }203 }204 var q amqp.Queue205 var err error206 if passive {207 q, err = ch.Channel.QueueDeclarePassive(name, durable, autoDelete, exclusive, noWait, args)208 } else {209 q, err = ch.Channel.QueueDeclare(name, durable, autoDelete, exclusive, noWait, args)210 }211 if err != nil {212 return nil, err213 }214 return &Queue{&q}, nil215}216func (ch *Channel) QueueDelete(name string, opt mocks.Option) (int, error) {217 var (218 ifUnused, ifEmpty, noWait bool219 )220 if v, ok := opt["ifUnused"]; ok {221 ifUnused, ok = v.(bool)222 if !ok {223 return 0, errors.New("ifUnused option is of type bool")224 }225 }226 if v, ok := opt["ifEmpty"]; ok {227 ifEmpty, ok = v.(bool)228 if !ok {229 return 0, errors.New("ifEmpty option is of type bool")230 }231 }232 if v, ok := opt["noWait"]; ok {233 noWait, ok = v.(bool)234 if !ok {235 return 0, errors.New("noWait option is of type bool")236 }237 }238 return ch.Channel.QueueDelete(name, ifUnused, ifEmpty, noWait)239}240// Qos controls how many bytes or messages will be handled by channel or connection.241func (ch *Channel) Qos(prefetchCount, prefetchSize int, global bool) error {242 return ch.Channel.Qos(prefetchCount, prefetchSize, global)243}244// NotifyClose registers a listener for close events.245// For more information see: https://godoc.org/github.com/rabbitmq/amqp091-go#Channel.NotifyClose246func (ch *Channel) NotifyClose(c chan mocks.Error) chan mocks.Error {247 amqpErr := ch.Channel.NotifyClose(make(chan *amqp.Error, cap(c)))248 go func() {249 for err := range amqpErr {250 var ne mocks.Error251 if err != nil {252 ne = utils.NewError(...

Full Screen

Full Screen

queue_submit_test.go

Source:queue_submit_test.go Github

copy

Full Screen

...34 require.True(t, v.FieldByName("pNext").IsNil())35 require.Equal(t, uint64(2), v.FieldByName("waitSemaphoreCount").Uint())36 require.Equal(t, uint64(1), v.FieldByName("commandBufferCount").Uint())37 require.Equal(t, uint64(3), v.FieldByName("signalSemaphoreCount").Uint())38 waitSemaphorePtr := unsafe.Pointer(v.FieldByName("pWaitSemaphores").Elem().UnsafeAddr())39 waitSemaphoreSlice := ([]driver.VkSemaphore)(unsafe.Slice((*driver.VkSemaphore)(waitSemaphorePtr), 2))40 require.Equal(t, waitSemaphore1.Handle(), waitSemaphoreSlice[0])41 require.Equal(t, waitSemaphore2.Handle(), waitSemaphoreSlice[1])42 waitDstStageMaskPtr := unsafe.Pointer(v.FieldByName("pWaitDstStageMask").Elem().UnsafeAddr())43 waitDstStageMaskSlice := ([]driver.VkPipelineStageFlags)(unsafe.Slice((*driver.VkPipelineStageFlags)(waitDstStageMaskPtr), 2))44 require.ElementsMatch(t, []driver.VkPipelineStageFlags{8, 128}, waitDstStageMaskSlice)45 commandBufferPtr := unsafe.Pointer(v.FieldByName("pCommandBuffers").Elem().UnsafeAddr())46 commandBufferSlice := ([]driver.VkCommandBuffer)(unsafe.Slice((*driver.VkCommandBuffer)(commandBufferPtr), 1))47 require.Equal(t, buffer.Handle(), commandBufferSlice[0])48 signalSemaphorePtr := unsafe.Pointer(v.FieldByName("pSignalSemaphores").Elem().UnsafeAddr())49 signalSemaphoreSlice := ([]driver.VkSemaphore)(unsafe.Slice((*driver.VkSemaphore)(signalSemaphorePtr), 3))50 require.Equal(t, signalSemaphore1.Handle(), signalSemaphoreSlice[0])51 require.Equal(t, signalSemaphore2.Handle(), signalSemaphoreSlice[1])52 require.Equal(t, signalSemaphore3.Handle(), signalSemaphoreSlice[2])53 }54 return core1_0.VKSuccess, nil55 })56 _, err := queue.Submit(fence, []core1_0.SubmitInfo{57 {58 CommandBuffers: []core1_0.CommandBuffer{buffer},59 WaitSemaphores: []core1_0.Semaphore{waitSemaphore1, waitSemaphore2},60 WaitDstStageMask: []core1_0.PipelineStageFlags{core1_0.PipelineStageVertexShader, core1_0.PipelineStageFragmentShader},61 SignalSemaphores: []core1_0.Semaphore{signalSemaphore1, signalSemaphore2, signalSemaphore3},62 },63 })64 require.NoError(t, err)65}66func TestSubmitToQueue_NoSignalSuccess(t *testing.T) {67 ctrl := gomock.NewController(t)68 defer ctrl.Finish()69 mockDriver := mock_driver.DriverForVersion(ctrl, common.Vulkan1_0)70 mockDevice := mocks.EasyMockDevice(ctrl, mockDriver)71 queue := internal_mocks.EasyDummyQueue(mockDriver, mockDevice)72 buffer := mocks.EasyMockCommandBuffer(ctrl)73 mockDriver.EXPECT().VkQueueSubmit(queue.Handle(), driver.Uint32(1), gomock.Not(nil), driver.VkFence(driver.NullHandle)).DoAndReturn(74 func(queue driver.VkQueue, submitCount driver.Uint32, pSubmits *driver.VkSubmitInfo, fence driver.VkFence) (common.VkResult, error) {75 submitSlices := ([]driver.VkSubmitInfo)(unsafe.Slice(pSubmits, int(submitCount)))76 for _, submit := range submitSlices {77 v := reflect.ValueOf(submit)78 require.Equal(t, uint64(4), v.FieldByName("sType").Uint()) // VK_STRUCTURE_TYPE_SUBMIT_INFO79 require.True(t, v.FieldByName("pNext").IsNil())80 require.Equal(t, uint64(0), v.FieldByName("waitSemaphoreCount").Uint())81 require.Equal(t, uint64(1), v.FieldByName("commandBufferCount").Uint())82 require.Equal(t, uint64(0), v.FieldByName("signalSemaphoreCount").Uint())83 require.True(t, v.FieldByName("pWaitSemaphores").IsNil())84 require.True(t, v.FieldByName("pWaitDstStageMask").IsNil())85 require.True(t, v.FieldByName("pSignalSemaphores").IsNil())86 commandBufferPtr := unsafe.Pointer(v.FieldByName("pCommandBuffers").Elem().UnsafeAddr())87 commandBufferSlice := ([]driver.VkCommandBuffer)(unsafe.Slice((*driver.VkCommandBuffer)(commandBufferPtr), 1))88 require.Equal(t, buffer.Handle(), commandBufferSlice[0])89 }90 return core1_0.VKSuccess, nil91 })92 _, err := queue.Submit(nil, []core1_0.SubmitInfo{93 {94 CommandBuffers: []core1_0.CommandBuffer{buffer},95 WaitSemaphores: []core1_0.Semaphore{},96 WaitDstStageMask: []core1_0.PipelineStageFlags{},97 SignalSemaphores: []core1_0.Semaphore{},98 },99 })100 require.NoError(t, err)101}102func TestSubmitToQueue_MismatchWaitSemaphores(t *testing.T) {103 ctrl := gomock.NewController(t)104 defer ctrl.Finish()105 mockDriver := mock_driver.DriverForVersion(ctrl, common.Vulkan1_0)106 mockDevice := mocks.EasyMockDevice(ctrl, mockDriver)107 queue := internal_mocks.EasyDummyQueue(mockDriver, mockDevice)108 buffer := mocks.EasyMockCommandBuffer(ctrl)109 waitSemaphore1 := mocks.EasyMockSemaphore(ctrl)110 waitSemaphore2 := mocks.EasyMockSemaphore(ctrl)111 _, err := queue.Submit(nil, []core1_0.SubmitInfo{112 {113 CommandBuffers: []core1_0.CommandBuffer{buffer},114 WaitSemaphores: []core1_0.Semaphore{waitSemaphore1, waitSemaphore2},115 WaitDstStageMask: []core1_0.PipelineStageFlags{core1_0.PipelineStageFragmentShader},116 SignalSemaphores: []core1_0.Semaphore{},117 },118 })119 require.EqualError(t, err, "attempted to submit with 2 wait semaphores but 1 dst stages- these should match")120}...

Full Screen

Full Screen

Wait

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 wg.Add(1)4 go func() {5 time.Sleep(2 * time.Second)6 fmt.Println("Hello from goroutine")7 wg.Done()8 }()9 wg.Wait()10 fmt.Println("Hello from main")11}

Full Screen

Full Screen

Wait

Using AI Code Generation

copy

Full Screen

1import (2func TestWait(t *testing.T) {3 m := new(mocks.Waiter)4 m.On("Wait").Return(nil)5 Wait(m)6 m.AssertExpectations(t)7}8import (9func TestWait(t *testing.T) {10 m := new(mocks.Waiter)11 m.On("Wait").Return(nil)12 Wait(m)13 m.AssertExpectations(t)14}15import (16func TestWait(t *testing.T) {17 m := new(mocks.Waiter)18 m.On("Wait").Return(nil)19 Wait(m)20 m.AssertExpectations(t)21}22import (23func TestWait(t *testing.T) {24 m := new(mocks.Waiter)25 m.On("Wait").Return(nil)26 Wait(m)27 m.AssertExpectations(t)28}29import (30func TestWait(t *testing.T) {31 m := new(mocks.Waiter)32 m.On("Wait").Return(nil)33 Wait(m)34 m.AssertExpectations(t)35}36import (37func TestWait(t *testing.T) {38 m := new(mocks.Waiter)39 m.On("Wait").Return(nil)40 Wait(m)41 m.AssertExpectations(t)42}43import (44func TestWait(t *testing.T) {45 m := new(mocks.Waiter)46 m.On("Wait").Return(nil)47 Wait(m)48 m.AssertExpectations(t)49}50import (

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful