master
go 49 lines 936 Bytes
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package jobmgr
4
5 import (
6 "testing"
7 "time"
8
9 "github.com/stretchr/testify/assert"
10 )
11
12 func TestFileStatusContains_DoesNotDeadlock(t *testing.T) {
13 tests := map[string]struct {
14 statuses []string
15 want bool
16 }{
17 "contains returns true for present status": {
18 statuses: []string{"running"},
19 want: true,
20 },
21 "contains returns false for missing status": {
22 statuses: []string{"failed"},
23 want: false,
24 },
25 }
26
27 for name, tc := range tests {
28 t.Run(name, func(t *testing.T) {
29 s := newFileStatus()
30 cfg := prepareUserCfg("success", "job")
31 s.add(cfg, "running")
32
33 done := make(chan struct{})
34 var got bool
35
36 go func() {
37 got = s.contains(cfg, tc.statuses...)
38 close(done)
39 }()
40
41 select {
42 case <-done:
43 assert.Equal(t, tc.want, got)
44 case <-time.After(200 * time.Millisecond):
45 t.Fatal("fileStatus.contains deadlocked")
46 }
47 })
48 }
49 }