Skip to content
Merged
Show file tree
Hide file tree
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
Rename assert condition
  • Loading branch information
mrodm committed Feb 25, 2025
commit d5521446333abd75d2089f0f39fc73bb6cc38a42
6 changes: 3 additions & 3 deletions docs/howto/system_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ for system tests.
| assert.hit_count | integer | | Exact number of documents to wait for being ingested. |
| assert.min_count | integer | | Minimum number of documents to wait for being ingested. |
| assert.fields_present | []string| | List of fields that must be present in the documents to stop waiting for new documents. |
| assert.seconds_without_change | duration | | Amount of time without ingesting new documents. |
| assert.ingestion_idle_time | duration | | Minimum time elapsed since the last document was ingested. |

For example, the `apache/access` data stream's `test-access-log-config.yml` is
shown below.
Expand Down Expand Up @@ -483,13 +483,13 @@ validated in this default scenario depends on how fast the documents are ingeste

There are other 4 options available:
- Wait for collecting exactly `assert.hit_count` documents into the data stream.
- It will fail if there are more than `assert.hit_count` documents ingested.
- It will fail if the final number of documents ingested into Elasticsearch is different from `assert.hit_count` documents.
- Wait for collecting at least `assert.min_count` documents into the data stream.
- Once there have been `assert.min_count` or more documents ingested, `elastic-package` will proceed to validate the documents.
- This could be used to ensure that a wide range of different documents have been ingested into Elasticsearch.
- Collect data into the data stream until all the fields defined in the list `assert.fields_present` are present in any of the documents.
- Each field in that list could be present in different documents.
- Wait for a period of time (`assert.seconds_without_change`) without ingesting new documents into given the data stream.
- Wait for a period of time (`assert.ingestion_idle_time`) without ingesting new documents into given the data stream.
- That period of time is just taken into account if at least there is one document in the data stream.
- It could be used when it is not known the exact number of documents that tests are going to be sending to Elasticsearch.

Expand Down
6 changes: 3 additions & 3 deletions internal/testrunner/runners/system/test_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ type testConfig struct {
// Minimum number of hits for a given test
MinCount int `config:"min_count"`

// Fields present
// FieldsPresent
FieldsPresent []string `config:"fields_present"`

// SecondsWithoutChange
SecondsWithoutChange time.Duration `config:"seconds_without_change"`
// IngestionIdleTime time elapsed since the last document was ingested
IngestionIdleTime time.Duration `config:"ingestion_idle_time"`
} `config:"assert"`

// NumericKeywordFields holds a list of fields that have keyword
Expand Down
10 changes: 5 additions & 5 deletions internal/testrunner/runners/system/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -1588,8 +1588,8 @@ func (r *tester) waitForDocs(ctx context.Context, config *testConfig, dataStream
return ret
}()

assertSecondsWithoutChange := func() bool {
if config.Assert.SecondsWithoutChange.Seconds() == 0 {
assertIngestionIdleTime := func() bool {
if config.Assert.IngestionIdleTime.Seconds() == 0 {
// not enabled
return true
}
Expand All @@ -1600,8 +1600,8 @@ func (r *tester) waitForDocs(ctx context.Context, config *testConfig, dataStream
prevTime = time.Now()
return false
}
if time.Since(prevTime) > config.Assert.SecondsWithoutChange {
logger.Debugf("No new documents ingested in %s", config.Assert.SecondsWithoutChange)
if time.Since(prevTime) > config.Assert.IngestionIdleTime {
logger.Debugf("No new documents ingested in %s", config.Assert.IngestionIdleTime)
return true
}
return false
Expand Down Expand Up @@ -1640,7 +1640,7 @@ func (r *tester) waitForDocs(ctx context.Context, config *testConfig, dataStream
// By default, config.Assert.MinCount is zero
assertMinCount := hits.size() > config.Assert.MinCount

return assertSecondsWithoutChange && assertFieldsPresent && assertMinCount && assertHitCount, nil
return assertIngestionIdleTime && assertFieldsPresent && assertMinCount && assertHitCount, nil
}, 1*time.Second, waitForDataTimeout)

if waitErr != nil {
Expand Down