MCPcopy
hub / github.com/etcd-io/bbolt / TestOpen_MultipleGoroutines

Function TestOpen_MultipleGoroutines

db_test.go:72–109  ·  view source on GitHub ↗

Regression validation for https://github.com/etcd-io/bbolt/pull/122. Tests multiple goroutines simultaneously opening a database.

(t *testing.T)

Source from the content-addressed store, hash-verified

70// Regression validation for https://github.com/etcd-io/bbolt/pull/122.
71// Tests multiple goroutines simultaneously opening a database.
72func 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.
112func TestOpen_ErrPathRequired(t *testing.T) {

Callers

nothing calls this directly

Calls 4

tempfileFunction · 0.85
AddMethod · 0.80
FatalfMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected