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: valueOr and withValue utilities #1079

Merged
merged 3 commits into from
Apr 4, 2024
Merged

fix: valueOr and withValue utilities #1079

merged 3 commits into from
Apr 4, 2024

Conversation

lchenut
Copy link
Contributor

@lchenut lchenut commented Apr 3, 2024

This PR fixes a double call when using the valueOr, withValue and toOpt templates.

The issue was found by @chaitanyaprem with a double call of a custom protocol here: https://github.com/waku-org/nwaku/blob/feat--nwaku-sync/waku/waku_sync/protocol.nim#L125-L126

libp2p/utility.nim Outdated Show resolved Hide resolved
tests/testutility.nim Outdated Show resolved Hide resolved
tests/testutility.nim Outdated Show resolved Hide resolved
Comment on lines 93 to 95
check false
else:
counter.inc()
Copy link
Contributor

Choose a reason for hiding this comment

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

we can probably extract it to a proc inside the test and avoid the repetition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean something like that?

proc testProc[T](val: Opt[T] | Option[T], counter: var int) =
  val.withValue(v):
    fail()
  else:
    counter.inc()
testProc(Opt.none(TestObj), counter)
testProc(none(TestObj), counter)

If there were more than two occurrences of this test I would do it, but I don't think it really brings something in this specific case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, the benefit is avoiding code duplication, which I believe is never desirable.

tests/testutility.nim Outdated Show resolved Hide resolved
Copy link
Contributor

@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 great. Thanks a lot for taking care of it and addressing the comments!

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 88.88889% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 84.56%. Comparing base (03f67d3) to head (5081127).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##           unstable    #1079      +/-   ##
============================================
- Coverage     84.82%   84.56%   -0.26%     
============================================
  Files            91       91              
  Lines         15428    15487      +59     
============================================
+ Hits          13087    13097      +10     
- Misses         2341     2390      +49     
Files Coverage Δ
libp2p/utility.nim 30.00% <88.88%> (-14.00%) ⬇️

... and 9 files with indirect coverage changes

@lchenut lchenut merged commit 09b3e11 into unstable Apr 4, 2024
9 checks passed
@lchenut lchenut deleted the fix-utilities branch April 4, 2024 15:15
SionoiS pushed a commit to waku-org/nwaku that referenced this pull request Apr 4, 2024
* feat: draft changes to use a storage manager for sync

* chore: address comments and resolve compilation issues

* chore: fixing test in progress

* chore: in progress time based storage creation

* fix: handle server not having storage

* chore: remove unused methods

* fix: import for trace logging

* fix: sync exports

* fix: duplicate invocation of dial due to a bug in valueOr vacp2p/nim-libp2p#1079

* chore: refactor and introduce sync session
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.

3 participants