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

Cleanup integration tests #757

Merged
merged 9 commits into from
May 23, 2024
Merged

Cleanup integration tests #757

merged 9 commits into from
May 23, 2024

Conversation

markspanbroek
Copy link
Member

@markspanbroek markspanbroek commented Mar 26, 2024

Moves the tests from the venerable testIntegration.nim into several new test modules.

  • testrestapi.nim: tests that exercise and test the REST API
  • testupdownload.nim: tests that exercise uploading and downloading content
  • testpurchasing.nim: tests for buying storage
  • testsales.nim: tests for selling storage
  • testmarketplace.nim: tests that exercise a combination of buying and selling storage

Part of #746

emizzle
emizzle previously approved these changes Mar 26, 2024
Copy link
Contributor

@emizzle emizzle left a comment

Choose a reason for hiding this comment

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

LGTM, except oddly there is a failing test 🤔

AuHau
AuHau previously approved these changes Mar 27, 2024
@markspanbroek
Copy link
Member Author

markspanbroek commented Mar 28, 2024

Failing test should be fixed in e62843d. Timing between test runner ( provider.getCurrentTime() ) and nodes ( clock.now ) was sometimes off by more than 10 seconds, failing the test.

I ran the test 100x, and it succeeded all the time.

@markspanbroek markspanbroek added this pull request to the merge queue Mar 28, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Mar 28, 2024
dryajov
dryajov previously approved these changes Apr 2, 2024
dryajov
dryajov previously approved these changes May 16, 2024
Copy link
Contributor

@dryajov dryajov left a comment

Choose a reason for hiding this comment

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

LGTM

@dryajov dryajov enabled auto-merge May 16, 2024 17:19
emizzle
emizzle previously approved these changes May 21, 2024
Copy link
Contributor

@emizzle emizzle left a comment

Choose a reason for hiding this comment

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

What are your thoughts on moving some of these tests over from twonodesuite to marketplacesuite?

@markspanbroek markspanbroek dismissed stale reviews from emizzle and dryajov via 69fd071 May 21, 2024 06:50
@markspanbroek
Copy link
Member Author

What are your thoughts on moving some of these tests over from twonodesuite to marketplacesuite?

I would say that that would be part of the work in #746, but not for this PR.

@markspanbroek
Copy link
Member Author

The intermittently failing test should be fixed in 97a57a1. The test would fail when the storage request was cancelled while a proof was being generated. The async state machine would then cancel the proving state, which triggers a chronos cancellation of future that calculates the proof. But the code that calculates the proof would catch and ignore the CancelledError (by catching all CatchableErrors). This pattern of catching CatchableError and not dealing with CancelledError properly happens in more places in the codebase. I tried to fix them all.

@emizzle
Copy link
Contributor

emizzle commented May 21, 2024

The intermittently failing test should be fixed in 97a57a1. The test would fail when the storage request was cancelled while a proof was being generated. The async state machine would then cancel the proving state, which triggers a chronos cancellation of future that calculates the proof. But the code that calculates the proof would catch and ignore the CancelledError (by catching all CatchableErrors). This pattern of catching CatchableError and not dealing with CancelledError properly happens in more places in the codebase. I tried to fix them all.

Right ok, this is a great catch! Just to clarify, you mean the initialproving state, correct? This is where the initial proof is generated, in the node.onProve callback, and if cancelled, would be caught here: 97a57a1#diff-1809bdd70926fdcad64f23f0974984916e79885ea5316ed2f2ac1457583bb3e5R701-R702

@markspanbroek
Copy link
Member Author

Just to clarify, you mean the initialproving state, correct?

No, if I remember correctly it was in the proving state. It had already filled the slot, but the other slots in the contract do not get filled, so eventually the contract is cancelled. This is also why the test was failing intermittently; the odds of it having to provide a proof at the same time that the storage contract expires is small.

@@ -244,7 +246,8 @@ proc rpcHandler(

if payment =? SignedState.init(msg.payment):
asyncSpawn b.handlePayment(peer, payment)

except CancelledError as error:
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're going to asyncSpawn handlePayment, there is no point in try/catch around it. Any escaping exception is converted to a Defect by asyncSpawn.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I have no idea why the error handling was here in the first place. I just added the extra case for CancelledError, but in the current code everything is asyncSpawned, and no errors will be raised anyway.

@@ -72,6 +74,8 @@ proc broadcast*(b: NetworkPeer, msg: Message) =
proc sendAwaiter() {.async.} =
try:
await b.send(msg)
except CancelledError as error:
raise error
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't re-raise in a proc that is asyncSpawn it will be terminate the application because it is converted to a Defect. Anything that is asyncSpawn should not raise exceptions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, I misread the except as being part of broadcast instead of sendAwaiter.

By the way, it seems that broadcast is unused? Should we remove it?

@@ -90,6 +90,8 @@ proc new*(
res += await stream.readOnce(addr data[res], len - res)
except LPStreamEOFError as exc:
trace "LPStreamChunker stream Eof", exc = exc.msg
except CancelledError as error:
raise error
except CatchableError as exc:
trace "CatchableError exception", exc = exc.msg
raise newException(Defect, exc.msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why we're converting this to a Defect, should maybe be simply re-raised?

Copy link
Member Author

Choose a reason for hiding this comment

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

No idea either, I just left that part alone.

markspanbroek and others added 2 commits May 22, 2024 09:38
No Exceptions can occur, only Defects, because everything
is asyncSpawned.

Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
Copy link
Member

@AuHau AuHau left a comment

Choose a reason for hiding this comment

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

Great catch! LGTM 👍

@dryajov dryajov added this pull request to the merge queue May 23, 2024
Merged via the queue into master with commit 3046b76 May 23, 2024
10 checks passed
@dryajov dryajov deleted the cleanup-integration-tests branch May 23, 2024 16:27
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.

None yet

4 participants