aboutsummaryrefslogtreecommitdiffstats
path: root/vm/dispatcher
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-08-02 17:46:52 +0200
committerAleksandr Nogikh <nogikh@google.com>2024-08-02 18:11:15 +0000
commit1786a2a82636054a2b049857ef8b011c7e539fb6 (patch)
treeeb45e40273ca48b5a9e7cb09bb81d1c4b5d84931 /vm/dispatcher
parente5b1f8e54a00370018f53737563d8e0e61da42c9 (diff)
vm/dispatcher: add TestPoolStress()
The test should aid the Go race detector to detect bugs in the dispatcher.Pool code.
Diffstat (limited to 'vm/dispatcher')
-rw-r--r--vm/dispatcher/pool_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/vm/dispatcher/pool_test.go b/vm/dispatcher/pool_test.go
index d27e83205..f48534e56 100644
--- a/vm/dispatcher/pool_test.go
+++ b/vm/dispatcher/pool_test.go
@@ -124,6 +124,33 @@ func TestPoolSplit(t *testing.T) {
<-done
}
+func TestPoolStress(t *testing.T) {
+ // The test to aid the race detector.
+ mgr := NewPool[*nilInstance](
+ 10,
+ func(idx int) (*nilInstance, error) {
+ return &nilInstance{}, nil
+ },
+ func(ctx context.Context, _ *nilInstance, _ UpdateInfo) {
+ <-ctx.Done()
+ },
+ )
+ done := make(chan bool)
+ ctx, cancel := context.WithCancel(context.Background())
+ go func() {
+ mgr.Loop(ctx)
+ close(done)
+ }()
+ for i := 0; i < 128; i++ {
+ go mgr.Run(func(ctx context.Context, _ *nilInstance, _ UpdateInfo) {
+ })
+ mgr.ReserveForRun(5 + i%5)
+ }
+
+ cancel()
+ <-done
+}
+
func makePool(count int) []testInstance {
var ret []testInstance
for i := 0; i < count; i++ {
@@ -169,3 +196,10 @@ func (ti *testInstance) Index() int {
func (ti *testInstance) Close() error {
return nil
}
+
+type nilInstance struct {
+}
+
+func (ni *nilInstance) Close() error {
+ return nil
+}