Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix intermittent failures in headers tests #145

Merged
merged 1 commit into from
May 18, 2023
Merged

Fix intermittent failures in headers tests #145

merged 1 commit into from
May 18, 2023

Conversation

setrofim
Copy link
Contributor

Split the "iv and partial iv present" test case into separate "iv present" and "partial iv present" cases in headers test.

The issue is that validateHeaderParameters takes a map of extracted header parameters and range's over them, validating each one. Ranging over maps in Go does not guarantee a stable order.

This meant that ether the "IV" or the "Partial IV" parameter could be checked first in the "iv and partial iv present" test case, resulting in different errors being reported on different runs.

The test harness only allows specifying one expected error, so when the order of the header params map iteration switched, the actual and expected errors didn't match resulting in test failure.

One way to fix it would be sort map values before iterating over them, however that would be an unnecessary overhead, since the order only matters in the context of the test (where a specific error is expected).

Therefore, the alternative solution is to split the test case into two, with only one possible error resulting from each.

@codecov
Copy link

codecov bot commented May 17, 2023

Codecov Report

Merging #145 (eb97d7e) into main (bfa9f54) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #145   +/-   ##
=======================================
  Coverage   92.77%   92.77%           
=======================================
  Files          10       10           
  Lines        1024     1024           
=======================================
  Hits          950      950           
  Misses         49       49           
  Partials       25       25           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@yogeshbdeshpande yogeshbdeshpande left a comment

Choose a reason for hiding this comment

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

LGTM!

Split the "iv and partial iv present" test case into separate "iv
present" and "partial iv present" cases in headers test.

The issue is that validateHeaderParameters takes a map of extracted
header parameters and range's over them, validating each one. Ranging
over maps in Go does not guarantee a stable order.

This meant that ether the "IV" or the "Partial IV" parameter could be
checked first in the "iv and partial iv present" test case, resulting in
different errors being reported on different runs.

The test harness only allows specifying one expected error, so when the
order of the header params map iteration switched, the actual and
expected errors didn't match resulting in test failure.

One way to fix it would be sort map values before iterating over them,
however that would be an unnecessary overhead, since the order only
matters in the context of the test (where a _specific_ error is
expected).

Therefore, the alternative solution is to split the test case into two,
with only one possible error resulting from each.

Also fix the test name to reflect what is actually being tested.

Signed-off-by: setrofim <setrofim@gmail.com>
Copy link
Contributor

@thomas-fossati thomas-fossati left a comment

Choose a reason for hiding this comment

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

thank you!

@setrofim setrofim merged commit 38be1cb into main May 18, 2023
@setrofim setrofim deleted the test-fix branch May 18, 2023 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants