Skip to content

Print error context when test fails#2437

Merged
enjoy-binbin merged 1 commit intovalkey-io:unstablefrom
enjoy-binbin:err_context
Aug 6, 2025
Merged

Print error context when test fails#2437
enjoy-binbin merged 1 commit intovalkey-io:unstablefrom
enjoy-binbin:err_context

Conversation

@enjoy-binbin
Copy link
Member

We used to did print the context but after #2276, we lost the context.

unstable:

*** Extract version and sha1 details from info command and print in tests/unit/info-command.tcl

now:

*** [err]: Extract version and sha1 details from info command and print in tests/unit/info-command.tcl
Expected '0' to be equal to '1' (context: type source line 7 file /xxx/info-command.tcl cmd {assert_equal 0 1} proc ::test)

We can see the different, we have provided enough context when asserting fail. Otherwise we need to scroll back (which is usually a lot of server logs) to see the context.

We used to did print the context but after valkey-io#2276, we lost the context.

unstable:
```
*** Extract version and sha1 details from info command and print in tests/unit/info-command.tcl
```

now:
```
*** [err]: Extract version and sha1 details from info command and print in tests/unit/info-command.tcl
Expected '0' to be equal to '1' (context: type source line 7 file /xxx/info-command.tcl cmd {assert_equal 0 1} proc ::test)
```

We can see the different, we have provided enough context when asserting fail.
Otherwise we need to scroll back (which is usually a lot of server logs) to see
the context.

Signed-off-by: Binbin <[email protected]>
set err "\[[colorstr red $status]\]: $data"
puts $err
set test_name [lindex [split $data "\n"] 0]
lappend ::failed_tests $test_name
Copy link
Member Author

Choose a reason for hiding this comment

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

we can print the whole err actually, it have more info

Copy link
Member

Choose a reason for hiding this comment

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

Oh so you are referring to the print at the end of the test? we do have a print when the test is reporting the error during the run right?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, the line 476 print the log, it happen during the run.

and here, the lappend ::failed_tests, we will print it at the end of the test.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok LGTM, if err has the test file name and the context, then we can append it directly.
But I don't think we had context before as mentioned in #2267.

Copy link
Member Author

Choose a reason for hiding this comment

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

only timeout test don't have the context and you made the change, the normal assert_xxx both have the context. Some other like may not have the context but we can fix it when we need it.

@codecov
Copy link

codecov bot commented Aug 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.38%. Comparing base (db11e41) to head (430138b).
⚠️ Report is 3 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #2437      +/-   ##
============================================
- Coverage     71.52%   71.38%   -0.15%     
============================================
  Files           125      125              
  Lines         69213    69213              
============================================
- Hits          49505    49406      -99     
- Misses        19708    19807      +99     

see 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@ranshid ranshid left a comment

Choose a reason for hiding this comment

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

Basically LGTM. There will be error print duplication, but I guess no harm in that.

set err "\[[colorstr red $status]\]: $data"
puts $err
set test_name [lindex [split $data "\n"] 0]
lappend ::failed_tests $test_name
Copy link
Member

Choose a reason for hiding this comment

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

Oh so you are referring to the print at the end of the test? we do have a print when the test is reporting the error during the run right?

@enjoy-binbin enjoy-binbin merged commit 094c80b into valkey-io:unstable Aug 6, 2025
51 checks passed
@enjoy-binbin enjoy-binbin deleted the err_context branch August 6, 2025 16:20
allenss-amazon pushed a commit to allenss-amazon/valkey-core that referenced this pull request Aug 19, 2025
We used to did print the context but after valkey-io#2276, we lost the context.

unstable:
```
*** Extract version and sha1 details from info command and print in tests/unit/info-command.tcl
```

now:
```
*** [err]: Extract version and sha1 details from info command and print in tests/unit/info-command.tcl
Expected '0' to be equal to '1' (context: type source line 7 file /xxx/info-command.tcl cmd {assert_equal 0 1} proc ::test)
```

We can see the different, we have provided enough context when asserting
fail. Otherwise we need to scroll back (which is usually a lot of server
logs) to see the context.

Signed-off-by: Binbin <[email protected]>
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