Regression validation for https://github.com/etcd-io/bbolt/pull/122. Tests multiple goroutines simultaneously opening a database.
(t *testing.T)
| 70 | // Regression validation for https://github.com/etcd-io/bbolt/pull/122. |
| 71 | // Tests multiple goroutines simultaneously opening a database. |
| 72 | func TestOpen_MultipleGoroutines(t *testing.T) { |
| 73 | if testing.Short() { |
| 74 | t.Skip("skipping test in short mode") |
| 75 | } |
| 76 | |
| 77 | const ( |
| 78 | instances = 30 |
| 79 | iterations = 30 |
| 80 | ) |
| 81 | path := tempfile() |
| 82 | defer os.RemoveAll(path) |
| 83 | var wg sync.WaitGroup |
| 84 | errCh := make(chan error, iterations*instances) |
| 85 | for iteration := 0; iteration < iterations; iteration++ { |
| 86 | for instance := 0; instance < instances; instance++ { |
| 87 | wg.Add(1) |
| 88 | go func() { |
| 89 | defer wg.Done() |
| 90 | db, err := bolt.Open(path, 0600, nil) |
| 91 | if err != nil { |
| 92 | errCh <- err |
| 93 | return |
| 94 | } |
| 95 | if err := db.Close(); err != nil { |
| 96 | errCh <- err |
| 97 | return |
| 98 | } |
| 99 | }() |
| 100 | } |
| 101 | wg.Wait() |
| 102 | } |
| 103 | close(errCh) |
| 104 | for err := range errCh { |
| 105 | if err != nil { |
| 106 | t.Fatalf("error from inside goroutine: %v", err) |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | // Ensure that opening a database with a blank path returns an error. |
| 112 | func TestOpen_ErrPathRequired(t *testing.T) { |