Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow to run several assert at the same time
  • Loading branch information
mrodm committed Feb 24, 2025
commit cf0fece0ebbb6a9d535e2b9a095393009122ed64
44 changes: 25 additions & 19 deletions internal/testrunner/runners/system/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -1583,49 +1583,55 @@ func (r *tester) waitForDocs(ctx context.Context, config *testConfig, dataStream
return ret, nil
}

if config.Assert.SecondsWithoutChange.Seconds() > 0 {
assertSecondsWithoutChange := func() bool {
if config.Assert.SecondsWithoutChange.Seconds() == 0 {
// not enabled
return true
}
if hits.size() == 0 {
// At least there should be one document ingested
return false, nil
return false
}
if oldHits != hits.size() {
prevTime = time.Now()
return false, nil
return false
}

if time.Since(prevTime) > config.Assert.SecondsWithoutChange {
logger.Debugf("No new documents ingested in %s", config.Assert.SecondsWithoutChange)
return true, nil
return true
}
return false, nil
}

if config.Assert.MinCount > 0 {
return hits.size() >= config.Assert.MinCount, nil
}
return false
}()

if len(config.Assert.FieldsPresent) > 0 {
assertFieldsPresent := func() bool {
if len(config.Assert.FieldsPresent) == 0 {
// not enabled
return true
}
if hits.size() == 0 {
return false, nil
// At least there should be one document ingested
return false
}
for _, f := range config.Assert.FieldsPresent {
found := false
for _, d := range hits.Fields {
if _, err := d.GetValue(f); err == nil {
logger.Debugf("> Found field %q in hits", f)
found = true
break
}
}
if !found {
logger.Debugf("Not found field %q in hits", f)
return false, nil
return false
}
logger.Debugf("> Found field %q in hits", f)
}
return true, nil
}
return true
}()

// By default, config.Assert.MinCount is zero
assertMinCount := hits.size() > config.Assert.MinCount

return hits.size() > 0, nil
return assertSecondsWithoutChange && assertFieldsPresent && assertMinCount, nil
}, 1*time.Second, waitForDataTimeout)

if waitErr != nil {
Expand Down