Skip to content

Commit

Permalink
update readme with instructions for go vcr (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmenglund authored Jul 23, 2023
1 parent cca85ab commit 9c02854
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ To run tests:
go test -v -timeout 30m ./...
```

### Go VCR

Some tests use [Go VCR](https://github.com/seborama/govcr), and they will use a cassette (recorded response) by default,
so if you want to re-record a cassette, set the environment variable `VCR_MODE` to `record`.

### Code Coverage

```
Expand Down
30 changes: 18 additions & 12 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (s *WriterSuite) TestCancellation() {
ctx, cancel := context.WithCancel(testCtx())
c := rockset.WriterConfig{
BatchDocumentCount: 30,
FlushInterval: time.Millisecond * 10,
FlushInterval: time.Millisecond * 20,
}
fa := &fakeAdder{}
w, err := rockset.NewWriter(c, fa)
Expand All @@ -98,7 +98,7 @@ func (s *WriterSuite) TestCancellation() {
Collection: "collection",
Data: testObject{},
}
time.Sleep(20 * time.Millisecond)
time.Sleep(30 * time.Millisecond)
w.C() <- rockset.WriteRequest{
Workspace: "workspace",
Collection: "collection",
Expand Down Expand Up @@ -226,16 +226,22 @@ func TestWriterIntegration(t *testing.T) {

assert.Equal(t, uint64(0), w.Stats().ErrorCount)
assert.Equal(t, writeCount, w.Stats().DocumentCount)
// sleep 1s to allow the data to be queryable
time.Sleep(time.Second)

resp, err := rc.Query(ctx, "SELECT COUNT(*) AS cnt FROM commons.writetest WHERE Bar = :name",
option.WithParameter("name", "string", name))
require.NoError(t, err)
// try to get the documents written back from Rockset
for i := 0; i < 5; i++ {
time.Sleep(time.Second)
resp, err := rc.Query(ctx, "SELECT COUNT(*) AS cnt FROM commons.writetest WHERE Bar = :name",
option.WithParameter("name", "string", name))
require.NoError(t, err)

require.Len(t, resp.Results, 1)
r := resp.Results[0]
cnt := r["cnt"]
count := cnt.(float64)
if uint64(count) == writeCount {
return
}
}

require.Len(t, resp.Results, 1)
r := resp.Results[0]
cnt := r["cnt"]
count := cnt.(float64)
assert.Equal(t, writeCount, uint64(count))
t.Errorf("failed to get %d records", writeCount)
}

0 comments on commit 9c02854

Please sign in to comment.