github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/fuzzer/queue/retry_test.go (about) 1 // Copyright 2024 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package queue 5 6 import ( 7 "context" 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestRetryerOnRestart(t *testing.T) { 14 q := Plain() 15 retryerObj := Retry(q) 16 17 q.Submit(&Request{Important: true}) 18 q.Submit(&Request{Important: false}) 19 20 // The requests must be retried forever. 21 req1 := retryerObj.Next() 22 req2 := retryerObj.Next() 23 for i := 0; i < 10; i++ { 24 req1.Done(&Result{Status: Restarted}) 25 req2.Done(&Result{Status: Restarted}) 26 assert.Equal(t, req1, retryerObj.Next()) 27 assert.Equal(t, req2, retryerObj.Next()) 28 } 29 30 // Once successful, requests should no longer appear. 31 req1.Done(&Result{Status: Success}) 32 req2.Done(&Result{Status: Success}) 33 34 assert.Equal(t, Success, req1.Wait(context.Background()).Status) 35 assert.Equal(t, Success, req2.Wait(context.Background()).Status) 36 37 assert.Nil(t, retryerObj.Next()) 38 assert.Nil(t, retryerObj.Next()) 39 } 40 41 func TestRetryerOnCrash(t *testing.T) { 42 q := Plain() 43 retryerObj := Retry(q) 44 45 // Unimportant requests will not be retried. 46 req := &Request{Important: false} 47 q.Submit(req) 48 assert.Equal(t, req, retryerObj.Next()) 49 req.Done(&Result{Status: Crashed}) 50 assert.Nil(t, retryerObj.Next()) 51 assert.Equal(t, Crashed, req.Wait(context.Background()).Status) 52 53 // Important requests will be retried once. 54 req = &Request{Important: true} 55 q.Submit(req) 56 assert.Equal(t, req, retryerObj.Next()) 57 req.Done(&Result{Status: Crashed}) 58 assert.Equal(t, req, retryerObj.Next()) 59 req.Done(&Result{Status: Success}) 60 assert.Nil(t, retryerObj.Next()) 61 assert.Equal(t, Success, req.Wait(context.Background()).Status) 62 63 // .. but not more than once. 64 req = &Request{Important: true} 65 q.Submit(req) 66 assert.Equal(t, req, retryerObj.Next()) 67 req.Done(&Result{Status: Crashed}) 68 assert.Equal(t, req, retryerObj.Next()) 69 req.Done(&Result{Status: Crashed}) 70 assert.Nil(t, retryerObj.Next()) 71 assert.Equal(t, Crashed, req.Wait(context.Background()).Status) 72 }