aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/fuzzer/queue/distributor_test.go
blob: 7bbf9c2e79aa3237448cd0ac177f2d1d3213072c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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))
}