MCPcopy
hub / github.com/hashicorp/go-memdb / TestMemDB_SingleWriter_MultiReader

Function TestMemDB_SingleWriter_MultiReader

memdb_test.go:11–44  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestMemDB_SingleWriter_MultiReader(t *testing.T) {
12 db, err := NewMemDB(testValidSchema())
13 if err != nil {
14 t.Fatalf("err: %v", err)
15 }
16
17 tx1 := db.Txn(true)
18 tx2 := db.Txn(false) // Should not block!
19 tx3 := db.Txn(false) // Should not block!
20 tx4 := db.Txn(false) // Should not block!
21
22 doneCh := make(chan struct{})
23 go func() {
24 defer close(doneCh)
25 db.Txn(true)
26 }()
27
28 select {
29 case <-doneCh:
30 t.Fatalf("should not allow another writer")
31 case <-time.After(10 * time.Millisecond):
32 }
33
34 tx1.Abort()
35 tx2.Abort()
36 tx3.Abort()
37 tx4.Abort()
38
39 select {
40 case <-doneCh:
41 case <-time.After(10 * time.Millisecond):
42 t.Fatalf("should allow another writer")
43 }
44}
45
46func TestMemDB_Snapshot(t *testing.T) {
47 db, err := NewMemDB(testValidSchema())

Callers

nothing calls this directly

Calls 4

TxnMethod · 0.95
NewMemDBFunction · 0.85
testValidSchemaFunction · 0.85
AbortMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…