Skip to content

Commit

Permalink
linearize streaming client to prevent flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erickpintor committed Apr 26, 2024
1 parent be555c2 commit fde55f7
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ import (
)

func TestStreaming(t *testing.T) {
t.Setenv(fauna.EnvFaunaEndpoint, fauna.EndpointLocal)
t.Setenv(fauna.EnvFaunaSecret, "secret")

client, clientErr := fauna.NewDefaultClient()
require.NoError(t, clientErr)
// NB. Use a linearized client to ensure that we get a txn time instead of a
// snapshot time when creating a stream value. That makes testing easier as
// we can trust that documents' timestamps created after a stream token can
// be used reliably to resume the stream.
client := fauna.NewClient(
"secret",
fauna.DefaultTimeouts(),
fauna.URL(fauna.EndpointLocal),
fauna.Linearized(true),
)

setupQ, _ := fauna.FQL(`
Collection.byName('StreamingTest')?.delete()
Collection.create({ name: 'StreamingTest' })
if (!Collection.byName('StreamingTest').exists()) {
Collection.create({ name: 'StreamingTest' })
} else {
StreamingTest.all().forEach(.delete())
}
`, nil)

_, err := client.Query(setupQ)
Expand Down

0 comments on commit fde55f7

Please sign in to comment.