diff options
Diffstat (limited to 'pkg/fuzzer/queue/distributor_test.go')
| -rw-r--r-- | pkg/fuzzer/queue/distributor_test.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/pkg/fuzzer/queue/distributor_test.go b/pkg/fuzzer/queue/distributor_test.go new file mode 100644 index 000000000..7bbf9c2e7 --- /dev/null +++ b/pkg/fuzzer/queue/distributor_test.go @@ -0,0 +1,48 @@ +// Copyright 2024 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package queue + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestDistributor(t *testing.T) { + q := Plain() + dist := Distribute(q) + + req := &Request{} + q.Submit(req) + assert.Equal(t, req, dist.Next(0)) + + q.Submit(req) + assert.Equal(t, req, dist.Next(1)) + + // Avoid VM 0. + req.Avoid = []ExecutorID{{VM: 0}} + q.Submit(req) + var noReq *Request + assert.Equal(t, noReq, dist.Next(0)) + assert.Equal(t, noReq, dist.Next(0)) + assert.Equal(t, req, dist.Next(1)) + + // If only VM 0 queries requests, it should eventually got it. + q.Submit(req) + assert.Equal(t, noReq, dist.Next(0)) + for { + got := dist.Next(0) + if got == req { + break + } + assert.Equal(t, noReq, got) + } + + // If all active VMs are in the avoid set, then they should get + // the request immidiatly. + assert.Equal(t, noReq, dist.Next(1)) + req.Avoid = []ExecutorID{{VM: 0}, {VM: 1}} + q.Submit(req) + assert.Equal(t, req, dist.Next(1)) +} |
