@@ -6,6 +6,7 @@ package queue
6
6
7
7
import (
8
8
"io/ioutil"
9
+ "sync"
9
10
"testing"
10
11
11
12
"code.gitea.io/gitea/modules/util"
@@ -22,6 +23,7 @@ func TestPersistableChannelQueue(t *testing.T) {
22
23
}
23
24
}
24
25
26
+ lock := sync.Mutex {}
25
27
queueShutdown := []func (){}
26
28
queueTerminate := []func (){}
27
29
@@ -41,8 +43,12 @@ func TestPersistableChannelQueue(t *testing.T) {
41
43
assert .NoError (t , err )
42
44
43
45
go queue .Run (func (shutdown func ()) {
46
+ lock .Lock ()
47
+ defer lock .Unlock ()
44
48
queueShutdown = append (queueShutdown , shutdown )
45
49
}, func (terminate func ()) {
50
+ lock .Lock ()
51
+ defer lock .Unlock ()
46
52
queueTerminate = append (queueTerminate , terminate )
47
53
})
48
54
@@ -69,7 +75,11 @@ func TestPersistableChannelQueue(t *testing.T) {
69
75
assert .Error (t , err )
70
76
71
77
// Now shutdown the queue
72
- for _ , callback := range queueShutdown {
78
+ lock .Lock ()
79
+ callbacks := make ([]func (), len (queueShutdown ))
80
+ copy (callbacks , queueShutdown )
81
+ lock .Unlock ()
82
+ for _ , callback := range callbacks {
73
83
callback ()
74
84
}
75
85
@@ -87,7 +97,11 @@ func TestPersistableChannelQueue(t *testing.T) {
87
97
}
88
98
89
99
// terminate the queue
90
- for _ , callback := range queueTerminate {
100
+ lock .Lock ()
101
+ callbacks = make ([]func (), len (queueTerminate ))
102
+ copy (callbacks , queueTerminate )
103
+ lock .Unlock ()
104
+ for _ , callback := range callbacks {
91
105
callback ()
92
106
}
93
107
@@ -110,8 +124,12 @@ func TestPersistableChannelQueue(t *testing.T) {
110
124
assert .NoError (t , err )
111
125
112
126
go queue .Run (func (shutdown func ()) {
127
+ lock .Lock ()
128
+ defer lock .Unlock ()
113
129
queueShutdown = append (queueShutdown , shutdown )
114
130
}, func (terminate func ()) {
131
+ lock .Lock ()
132
+ defer lock .Unlock ()
115
133
queueTerminate = append (queueTerminate , terminate )
116
134
})
117
135
@@ -122,10 +140,19 @@ func TestPersistableChannelQueue(t *testing.T) {
122
140
result4 := <- handleChan
123
141
assert .Equal (t , test2 .TestString , result4 .TestString )
124
142
assert .Equal (t , test2 .TestInt , result4 .TestInt )
125
- for _ , callback := range queueShutdown {
143
+
144
+ lock .Lock ()
145
+ callbacks = make ([]func (), len (queueShutdown ))
146
+ copy (callbacks , queueShutdown )
147
+ lock .Unlock ()
148
+ for _ , callback := range callbacks {
126
149
callback ()
127
150
}
128
- for _ , callback := range queueTerminate {
151
+ lock .Lock ()
152
+ callbacks = make ([]func (), len (queueTerminate ))
153
+ copy (callbacks , queueTerminate )
154
+ lock .Unlock ()
155
+ for _ , callback := range callbacks {
129
156
callback ()
130
157
}
131
158
0 commit comments