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

test(flaky): Log checkExpiring failure #1018

Merged
merged 3 commits into from
Feb 6, 2024
Merged

Conversation

AlejandroCabeza
Copy link
Collaborator

Changed check to assert to leverage the capability of returning a message on failure, as check does not have that capability (that I know of) and using logs (e.g.: error, debug) was not working for me.

Copy link

codecov bot commented Feb 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (eb0890c) 83.18% compared to head (77519a7) 83.18%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           unstable    #1018   +/-   ##
=========================================
  Coverage     83.18%   83.18%           
=========================================
  Files            91       91           
  Lines         15349    15349           
=========================================
  Hits          12768    12768           
  Misses         2581     2581           

@AlejandroCabeza AlejandroCabeza enabled auto-merge (squash) February 1, 2024 14:54
libp2p.nimble Outdated Show resolved Hide resolved
@@ -122,7 +122,8 @@ proc checkExpiringInternal(cond: proc(): bool {.raises: [], gcsafe.} ): Future[b
await sleepAsync(1.millis)

template checkExpiring*(code: untyped): untyped =
check await checkExpiringInternal(proc(): bool = code)
let result = await checkExpiringInternal(proc(): bool = code)
assert result, "[TIMEOUT] Test failed due to the check timeout. Consider adjusting it."
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this is gonna change the current output that shows the current and expected values.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@AlejandroCabeza could you please make sure the current behavior isn't changed? Isn't it possible to add this message to the check proc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As far as I know, there's no way to add a message to the check template; hence the change. That's why I suggested the possibility of PRing the unittest library with said change, in the case somebody's able to implement it.

In any case, and answering your first comment: I think this shouldn't change the output, at least it doesn't seem that way. Having a closer look at checkExpiring you can notice the previous check was done over the returning value of checkExpiringInternal, which in turn is a simplified bool.

I believe the better output message that check generally outputs is due to it receving the raw conditions and parsing the syntax tree, which is not possible as this is currently defined. Due to that, I also believe assert will not change in any way the behaviour previously defined.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're right, it shouldn't change the current behavior. But it'd probably be better to make checkExpiring behave like check, if it's possible to do that. Timeout isn't the only possible failure if the conditions are always false. Does it make sense?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It'd be nice to make it behave like so, but I don't consider myself capable of manipulating Nim's syntax trees just yet.

Copy link
Collaborator

Choose a reason for hiding this comment

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

My last comment is wrong. When the conditions are always false, it'll always fail with a timeout, but we won't see what the different values are.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because if it fails with a timeout it's because the async proc won't have completed, meaning there are no values to check against.

Copy link
Collaborator

Choose a reason for hiding this comment

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

we can try to do it in another PR.

Copy link
Collaborator

@diegomrsantos diegomrsantos left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for that. Maybe only the tittle isn't up-to-date.

@AlejandroCabeza AlejandroCabeza merged commit 04af0c4 into unstable Feb 6, 2024
11 checks passed
@AlejandroCabeza AlejandroCabeza deleted the log-check-expiring branch February 6, 2024 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants