Skip to content

Commit a0563de

Browse files
authored
test: make ut of WAL stable (#116)
1 parent 1a210de commit a0563de

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

internal/store/wal/wal_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"os"
2121
"path/filepath"
22+
"sync/atomic"
2223
"testing"
2324

2425
// third-party libraries.
@@ -50,7 +51,7 @@ func TestWAL_AppendOne(t *testing.T) {
5051
}))
5152
n, _ := wal.AppendOne(data1).Wait()
5253

53-
// Invoke callback of appand data0, before appand data1 return.
54+
// Invoke callback of append data0, before append data1 return.
5455
So(done, ShouldBeTrue)
5556
So(n, ShouldEqual, 21)
5657
So(wal.wb.Size(), ShouldEqual, 21)
@@ -94,10 +95,12 @@ func TestWAL_AppendOne(t *testing.T) {
9495
wal, err := NewWAL(walDir, WithFileSize(fileSize))
9596
So(err, ShouldBeNil)
9697

97-
var done bool
98-
wal.AppendOne(data0, WithCallback(func(_ Result) {
99-
done = true
100-
}))
98+
var inflight int32 = 100
99+
for i := int32(0); i < inflight; i++ {
100+
wal.AppendOne(data0, WithCallback(func(_ Result) {
101+
atomic.AddInt32(&inflight, -1)
102+
}))
103+
}
101104

102105
wal.Close()
103106

@@ -107,7 +110,7 @@ func TestWAL_AppendOne(t *testing.T) {
107110
wal.Wait()
108111

109112
// NOTE: All appends are guaranteed to return before wal is closed.
110-
So(done, ShouldBeTrue)
113+
So(atomic.LoadInt32(&inflight), ShouldBeZeroValue)
111114

112115
// NOTE: There is no guarantee that data0 will be successfully written.
113116
// So(wal.wb.Size(), ShouldEqual, 10)

0 commit comments

Comments
 (0)