|
6 | 6 | "context"
|
7 | 7 | "fmt"
|
8 | 8 | "math/rand"
|
9 |
| - "os" |
10 | 9 | "reflect"
|
11 | 10 | "testing"
|
12 | 11 | "time"
|
@@ -258,7 +257,23 @@ func isNotFoundError(err error) bool {
|
258 | 257 | // For details, check out https://molecula.atlassian.net/browse/CORE-919
|
259 | 258 | func TestIndex_RecreateFieldOnRestart(t *testing.T) {
|
260 | 259 | c := test.MustRunUnsharedCluster(t, 1)
|
261 |
| - defer c.Close() |
| 260 | + defer func() { |
| 261 | + // We anticipate a deadlock, and if we hit the deadlock, |
| 262 | + // closing would ALSO deadlock, so we won't want to do that. |
| 263 | + // |
| 264 | + // The alternative, of trying to call os.Exit, prevents us |
| 265 | + // from reporting anything at all, because testing doesn't |
| 266 | + // actually display messages until it's done. |
| 267 | + // |
| 268 | + // So, if we're bailing because of a fatal error, we don't |
| 269 | + // try to close the cluster, because Something Went Wrong and |
| 270 | + // it may well have been a deadlock. We leak one cluster on |
| 271 | + // a failed test, but we correctly report the test as failed |
| 272 | + // before also reporting the unclosed resources. |
| 273 | + if !t.Failed() { |
| 274 | + c.Close() |
| 275 | + } |
| 276 | + }() |
262 | 277 |
|
263 | 278 | // create index
|
264 | 279 | indexName := fmt.Sprintf("idx_%d", rand.Uint64())
|
@@ -310,15 +325,7 @@ func TestIndex_RecreateFieldOnRestart(t *testing.T) {
|
310 | 325 | }()
|
311 | 326 | select {
|
312 | 327 | case <-time.After(10 * time.Second):
|
313 |
| - // We have to use os.Exit here instead of t.Fatal or panic since |
314 |
| - // on panic, deferred statements are still ran. Given that |
315 |
| - // we have deferred cluster.Close(), it deadlocks on the same |
316 |
| - // issue this test is, well, is testing on. |
317 |
| - // With os.Exit, the process exits at that point without running the |
318 |
| - // deferred actions. This is more of a work-around fix to make the |
319 |
| - // test meaningful on timeout. |
320 |
| - t.Logf("recreating field took too long") |
321 |
| - os.Exit(1) |
| 328 | + t.Fatal("recreating field took too long") |
322 | 329 | case err := <-errCh:
|
323 | 330 | if err != nil {
|
324 | 331 | t.Fatal(err)
|
|
0 commit comments