Skip to content

Commit

Permalink
Merge pull request #1701 from josephschorr/flaky-test
Browse files Browse the repository at this point in the history
Fix flakiness of HLC changes test
  • Loading branch information
josephschorr authored Jan 2, 2024
2 parents 8630789 + 355d6c6 commit ffdb1a7
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions internal/datastore/common/changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"context"
"slices"
"sort"
"strings"
"testing"
Expand Down Expand Up @@ -468,16 +469,29 @@ func TestHLCSameRevision(t *testing.T) {
remaining := ch.AsRevisionChanges(revisions.HLCKeyLessThanFunc)
require.Equal(t, 1, len(remaining))

expected := []*core.RelationTupleUpdate{
tuple.Touch(tuple.MustParse("document:foo#viewer@user:tom")),
tuple.Touch(tuple.MustParse("document:foo#viewer@user:sarah")),
}
slices.SortFunc(expected, func(i, j *core.RelationTupleUpdate) int {
iStr := tuple.StringWithoutCaveat(i.Tuple)
jStr := tuple.StringWithoutCaveat(j.Tuple)
return strings.Compare(iStr, jStr)
})

slices.SortFunc(remaining[0].RelationshipChanges, func(i, j *core.RelationTupleUpdate) int {
iStr := tuple.StringWithoutCaveat(i.Tuple)
jStr := tuple.StringWithoutCaveat(j.Tuple)
return strings.Compare(iStr, jStr)
})

require.Equal(t, []datastore.RevisionChanges{
{
Revision: rev0,
RelationshipChanges: []*core.RelationTupleUpdate{
tuple.Touch(tuple.MustParse("document:foo#viewer@user:tom")),
tuple.Touch(tuple.MustParse("document:foo#viewer@user:sarah")),
},
DeletedNamespaces: []string{},
DeletedCaveats: []string{},
ChangedDefinitions: []datastore.SchemaDefinition{},
Revision: rev0,
RelationshipChanges: expected,
DeletedNamespaces: []string{},
DeletedCaveats: []string{},
ChangedDefinitions: []datastore.SchemaDefinition{},
},
}, remaining)
}
Expand Down

0 comments on commit ffdb1a7

Please sign in to comment.