Remove failing blockstore test with context
Why is it failing: process is started, cancel() is called, between we satart listening to the channels in select statemnet there is race of three things that can happent: 1. Task can complete 2. Task can start closing <- expected 3. Task already closed This race causes failures of the test. It is basing heavily on race of conditions where the task not closing, nor the task is completed before channels are being listened. It is quite impossible to resolve without adding bunch of timings in there, which we want to avoid, as there is no atomic "send message on channel and select" in Golang License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
Jun 15, 2016 at 20:26 UTC
5a08e9e08a1207851ce4e4cdab333f8a0e1ef47d
1 file changed
+35
-90
blocks/blockstore/blockstore_test.go
+35
-90
@@ -117,97 +117,42 @@ func TestAllKeysRespectsContext(t *testing.T) {
117
errors <- nil // a nil one to signal break
118
}
119
120
- // Once without context, to make sure it all works
121
- {
122
- var results dsq.Results
123
- var resultsmu = make(chan struct{})
124
- resultChan := make(chan dsq.Result)
125
- d.SetFunc(func(q dsq.Query) (dsq.Results, error) {
126
- results = dsq.ResultsWithChan(q, resultChan)
127
- resultsmu <- struct{}{}
128
- return results, nil
129
- })
130
-
131
- go getKeys(context.Background())
132
-
133
- // make sure it's waiting.
134
- <-started
135
- <-resultsmu
136
- select {
137
- case <-done:
138
- t.Fatal("sync is wrong")
139
- case <-results.Process().Closing():
140
- t.Fatal("should not be closing")
141
- case <-results.Process().Closed():
142
- t.Fatal("should not be closed")
143
- default:
144
- }
145
-
146
- e := dsq.Entry{Key: BlockPrefix.ChildString("foo").String()}
147
- resultChan <- dsq.Result{Entry: e} // let it go.
148
- close(resultChan)
149
- <-done // should be done now.
150
- <-results.Process().Closed() // should be closed now
151
-
152
- // print any errors
153
- for err := range errors {
154
- if err == nil {
155
- break
156
- }
157
- t.Error(err)
158
- }
159
- }
160
-
161
- // Once with
162
- {
163
- var results dsq.Results
164
- var resultsmu = make(chan struct{})
165
- resultChan := make(chan dsq.Result)
166
- d.SetFunc(func(q dsq.Query) (dsq.Results, error) {
167
- results = dsq.ResultsWithChan(q, resultChan)
168
- resultsmu <- struct{}{}
169
- return results, nil
170
- })
171
-
172
- ctx, cancel := context.WithCancel(context.Background())
173
- go getKeys(ctx)
174
-
175
- // make sure it's waiting.
176
- <-started
177
- <-resultsmu
178
- select {
179
- case <-done:
180
- t.Fatal("sync is wrong")
181
- case <-results.Process().Closing():
182
- t.Fatal("should not be closing")
183
- case <-results.Process().Closed():
184
- t.Fatal("should not be closed")
185
- default:
186
- }
187
-
188
- cancel() // let it go.
189
-
190
- select {
191
- case <-done:
192
- t.Fatal("sync is wrong")
193
- case <-results.Process().Closed():
194
- t.Fatal("should not be closed") // should not be closed yet.
195
- case <-results.Process().Closing():
196
- // should be closing now!
197
- t.Log("closing correctly at this point.")
198
- }
199
-
200
- close(resultChan)
201
- <-done // should be done now.
202
- <-results.Process().Closed() // should be closed now
203
-
204
- // print any errors
205
- for err := range errors {
206
- if err == nil {
207
- break
208
- }
209
- t.Error(err)
120
+ var results dsq.Results
121
+ var resultsmu = make(chan struct{})
122
+ resultChan := make(chan dsq.Result)
123
+ d.SetFunc(func(q dsq.Query) (dsq.Results, error) {
124
+ results = dsq.ResultsWithChan(q, resultChan)
125
+ resultsmu <- struct{}{}
126
+ return results, nil
127
+ })
128
+
129
+ go getKeys(context.Background())
130
+
131
+ // make sure it's waiting.
132
+ <-started
133
+ <-resultsmu
134
+ select {
135
+ case <-done:
136
+ t.Fatal("sync is wrong")
137
+ case <-results.Process().Closing():
138
+ t.Fatal("should not be closing")
139
+ case <-results.Process().Closed():
140
+ t.Fatal("should not be closed")
141
+ default:
142
+ }
143
+
144
+ e := dsq.Entry{Key: BlockPrefix.ChildString("foo").String()}
145
+ resultChan <- dsq.Result{Entry: e} // let it go.
146
+ close(resultChan)
147
+ <-done // should be done now.
148
+ <-results.Process().Closed() // should be closed now
149
+
150
+ // print any errors
151
+ for err := range errors {
152
+ if err == nil {
153
+ break
154
}
155
+ t.Error(err)
156
}
157
158
}