execqueue_test.go 607 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package execqueue
  4. import (
  5. "context"
  6. "sync/atomic"
  7. "testing"
  8. )
  9. func TestExecQueue(t *testing.T) {
  10. ctx := context.Background()
  11. var n atomic.Int32
  12. q := &ExecQueue{}
  13. defer q.Shutdown()
  14. q.Add(func() { n.Add(1) })
  15. q.Wait(ctx)
  16. if got := n.Load(); got != 1 {
  17. t.Errorf("n=%d; want 1", got)
  18. }
  19. }
  20. // Test that RunSync doesn't hold q.mu and block Shutdown
  21. // as we saw in tailscale/tailscale#18502
  22. func TestExecQueueRunSyncLocking(t *testing.T) {
  23. q := &ExecQueue{}
  24. q.RunSync(t.Context(), func() {
  25. q.Shutdown()
  26. })
  27. }