| 1 | package historycatalog |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "testing" |
| 7 | "time" |
| 8 | ) |
| 9 | |
| 10 | func TestCloseCanBeAwaitedAfterCanceledCaller(t *testing.T) { |
| 11 | catalog, err := Open(context.Background(), Options{InMemory: true}) |
| 12 | if err != nil { |
| 13 | t.Fatalf("open: %v", err) |
| 14 | } |
| 15 | canceled, cancel := context.WithCancel(context.Background()) |
| 16 | cancel() |
| 17 | if err := catalog.Close(canceled); err != nil && !errors.Is(err, context.Canceled) { |
| 18 | t.Fatalf("first close: %v", err) |
| 19 | } |
| 20 | ctx, stop := context.WithTimeout(context.Background(), 5*time.Second) |
| 21 | defer stop() |
| 22 | if err := catalog.Close(ctx); err != nil { |
| 23 | t.Fatalf("await eventual close: %v", err) |
| 24 | } |
| 25 | if err := catalog.db.Ping(); err == nil { |
| 26 | t.Fatal("database remained open after close completion") |
| 27 | } |
| 28 | } |
| 29 |