TestOpenDBConcurrentDoesNotBusy pins that two parallel OpenDB calls on the same path don't race during schema setup. Without busy_timeout applied at open time, the loser hits SQLITE_BUSY on `pragma table_info(tasks)` during runMigrations on slow runners — observed as a flaky CI failure on the app-le
(t *testing.T)
| 69 | // table_info(tasks)` during runMigrations on slow runners — observed |
| 70 | // as a flaky CI failure on the app-level concurrent-do test. |
| 71 | func TestOpenDBConcurrentDoesNotBusy(t *testing.T) { |
| 72 | path := filepath.Join(t.TempDir(), "flow.db") |
| 73 | const n = 8 |
| 74 | var wg sync.WaitGroup |
| 75 | errs := make([]error, n) |
| 76 | wg.Add(n) |
| 77 | for i := range n { |
| 78 | go func() { |
| 79 | defer wg.Done() |
| 80 | db, err := OpenDB(path) |
| 81 | if err != nil { |
| 82 | errs[i] = err |
| 83 | return |
| 84 | } |
| 85 | db.Close() |
| 86 | }() |
| 87 | } |
| 88 | wg.Wait() |
| 89 | for i, err := range errs { |
| 90 | if err != nil { |
| 91 | t.Errorf("goroutine %d: %v", i, err) |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | func TestProjectCRUD(t *testing.T) { |
| 97 | db := openTempDB(t) |