Skip to content

Commit

Permalink
test: Fix refreshing of docs in change detector (#2832)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves #2812 

## Description

This fixes two issues in `refreshDocuments`.
- `DocIndex`es were not accounted for in refresh documents, this was
introduced a while ago and lay hiding until recently
- Creating multiple docs in a single action was not handled
  • Loading branch information
AndrewSisley authored Jul 15, 2024
1 parent d73b05b commit 3500ce3
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions tests/integration/utils2.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,33 +870,48 @@ func refreshDocuments(
}

for i := 0; i < startActionIndex; i++ {
// We need to add the existing documents in the order in which the test case lists them
// otherwise they cannot be referenced correctly by other actions.
switch action := s.testCase.Actions[i].(type) {
case CreateDoc:
// Just use the collection from the first relevant node, as all will be the same for this
// purpose.
collection := getNodeCollections(action.NodeID, s.collections)[0][action.CollectionID]

// We need to add the existing documents in the order in which the test case lists them
// otherwise they cannot be referenced correctly by other actions.
doc, err := client.NewDocFromJSON([]byte(action.Doc), collection.Definition())
if err != nil {
// If an err has been returned, ignore it - it may be expected and if not
// the test will fail later anyway
continue
var doc *client.Document
var docs []*client.Document
var err error
if action.DocMap != nil {
substituteRelations(s, action)
doc, err = client.NewDocFromMap(action.DocMap, collection.Definition())
docs = append(docs, doc)
} else if client.IsJSONArray([]byte(action.Doc)) {
docs, err = client.NewDocsFromJSON([]byte(action.Doc), collection.Definition())
} else {
doc, err = client.NewDocFromJSON([]byte(action.Doc), collection.Definition())
docs = append(docs, doc)
}

ctx := makeContextForDocCreate(s, s.ctx, &action)

// The document may have been mutated by other actions, so to be sure we have the latest
// version without having to worry about the individual update mechanics we fetch it.
doc, err = collection.Get(ctx, doc.ID(), false)
if err != nil {
// If an err has been returned, ignore it - it may be expected and if not
// the test will fail later anyway
continue
}

s.documents[action.CollectionID] = append(s.documents[action.CollectionID], doc)
for _, doc := range docs {
ctx := makeContextForDocCreate(s, s.ctx, &action)

// The document may have been mutated by other actions, so to be sure we have the latest
// version without having to worry about the individual update mechanics we fetch it.
doc, err = collection.Get(ctx, doc.ID(), false)
if err != nil {
// If an err has been returned, ignore it - it may be expected and if not
// the test will fail later anyway
continue
}

s.documents[action.CollectionID] = append(s.documents[action.CollectionID], doc)
}
}
}
}
Expand Down

0 comments on commit 3500ce3

Please sign in to comment.