Skip to content

EQL: support multiple test outcomes for non-deterministic TOML tests#87964

Merged
luigidellaquila merged 3 commits intoelastic:feature/eql_samplesfrom
luigidellaquila:fix/eql_deterministic_sample_tests
Jun 30, 2022
Merged

EQL: support multiple test outcomes for non-deterministic TOML tests#87964
luigidellaquila merged 3 commits intoelastic:feature/eql_samplesfrom
luigidellaquila:fix/eql_deterministic_sample_tests

Conversation

@luigidellaquila
Copy link
Copy Markdown
Contributor

Some EQL test cases (Sample test cases in particular) are not completely deterministic; their outcome can change based on how the data are indexed on multiple shards.

This PR allows to define multiple possible outcomes (expected_event_ids) for a toml test case.

Both the following are now valid:

  • single array of IDs: only one possible outcome is possible for this test
expected_event_ids  = [12, 13, 14]
  • array of arrays of IDs: any of the ID arrays is a valid outcome for the test
expected_event_ids  = [
  [12, 13, 14],
  [12, 13, 15]
]

@luigidellaquila luigidellaquila marked this pull request as ready for review June 23, 2022 16:53
@elasticmachine elasticmachine added the Team:QL (Deprecated) Meta label for query languages team label Jun 23, 2022
@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-ql (Team:QL)

@luigidellaquila luigidellaquila requested a review from astefan June 23, 2022 16:53
Copy link
Copy Markdown
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good.
I've left some comments. Nothing major.

"unexpected result for spec[{}] [{}] -> {} vs {}",
name,
query,
Arrays.toString(eventIds.get(0)),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract eventIds.get(0) once and re-use it.

actual
);
} else {
for (long[] expected : eventIds) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move boolean succeeded = false; here, because this is the if branch that needs it.

);

fail(msg);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary empty line.

Comment on lines +10 to +13
expected_event_ids = [
[17, 26, 16, 13, 23, 110],
[17, 26, 16, 110, 23, 33]
]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep the original format, please?
17,26,16 corresponds to the first join key ["doom","redhad"] and 13,23,110 corresponds to ["farcry", "win10"]. And each pair of three ids is put on each line so that each line corresponds to the same line in the join_keys section.

So, with the updated format it should look like

Suggested change
expected_event_ids = [
[17, 26, 16, 13, 23, 110],
[17, 26, 16, 110, 23, 33]
]
expected_event_ids = [
[17, 26, 16,
13, 23, 110],
[17, 26, 16,
110, 23, 33]
]

@@ -3,11 +3,14 @@ name = "anyRulesWithOneDifferentNameKey"
query = '''
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the top of this file, at least, please add a comment describing this syntax (array of arrays in case of multiple possible solutions).


import java.util.List;

public class EqlSpecLoaderTests extends ESTestCase {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test is not really needed. The description to be added to test_sample.toml and the tests in samples should be enough.

private String[] tags;
private String query;
private long[] expectedEventIds;
private List<long[]> expectedEventIds;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add a comment to this line as well, mentioning a list of possible valid results to check.

@astefan astefan added the >test Issues or PRs that are addressing/adding tests label Jun 24, 2022
Copy link
Copy Markdown
Contributor

@bpintea bpintea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

int i = 0;
for (Object obj : arr) {
tags[i] = (String) obj;
tags[i++] = (String) obj;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

expected,
actual
);
if (eventIds.size() == 1) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this case singled out just to make use of assertArrayEquals()? Otherwise using the code in the other branch should be enough, imo. The message could be customized based on list size.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just because assertArrayEquals() returns a more precise error message (ie. it also points to the exact array element that differs), that is useful in that specific case, but does not make much sense when you have multiple possible results

@luigidellaquila luigidellaquila merged commit 2202e30 into elastic:feature/eql_samples Jun 30, 2022
@luigidellaquila luigidellaquila mentioned this pull request Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/EQL EQL querying >enhancement Team:QL (Deprecated) Meta label for query languages team >test Issues or PRs that are addressing/adding tests v8.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants