summaryrefslogtreecommitdiffhomepage
path: root/util/execqueue/execqueue_test.go
blob: c9f3a449ef67e7eb88f1636484b17b82c6dc75d5 (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
// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause

package execqueue

import (
	"context"
	"sync/atomic"
	"testing"
)

func TestExecQueue(t *testing.T) {
	ctx := context.Background()
	var n atomic.Int32
	q := &ExecQueue{}
	defer q.Shutdown()
	q.Add(func() { n.Add(1) })
	q.Wait(ctx)
	if got := n.Load(); got != 1 {
		t.Errorf("n=%d; want 1", got)
	}
}

// Test that RunSync doesn't hold q.mu and block Shutdown
// as we saw in tailscale/tailscale#18502
func TestExecQueueRunSyncLocking(t *testing.T) {
	q := &ExecQueue{}
	q.RunSync(t.Context(), func() {
		q.Shutdown()
	})
}