Skip to content

Commit

Permalink
add unit test for race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
hangxie committed Sep 17, 2023
1 parent 03f098e commit 1b3fb4e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PACKAGES=`go list ./... | grep -v example`

test:
go test --count 1 -v -cover ${PACKAGES}
go test -race --count 1 -v -cover ${PACKAGES}

format:
go fmt github.com/xitongsys/parquet-go/...
Expand Down
13 changes: 13 additions & 0 deletions writer/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,16 @@ func TestNewWriterWithInvaidFile(t *testing.T) {
assert.Nil(t, pw)
assert.ErrorIs(t, err, testWriteErr)
}

func TestWriteStopRaceConditionOnError(t *testing.T) {
var buf bytes.Buffer
fw := writerfile.NewWriterFile(&buf)
pw, err := NewJSONWriter(`{"Tag":"name=parquet-go-root","Fields":[{"Tag":"name=x, type=INT64"}]}`, fw, 4)
assert.NoError(t, err)

for i := 0; i < 1000; i++ {
entry := fmt.Sprintf(`{"not-x":%d}`, i)
assert.NoError(t, pw.Write(entry))
}
assert.Error(t, pw.WriteStop())
}

0 comments on commit 1b3fb4e

Please sign in to comment.