Skip to content

Fix confusing and incorrect test condition#571

Merged
nothingmuch merged 2 commits intopayjoin:masterfrom
nothingmuch:v1-to-v2-test-202-bug
Mar 12, 2025
Merged

Fix confusing and incorrect test condition#571
nothingmuch merged 2 commits intopayjoin:masterfrom
nothingmuch:v1-to-v2-test-202-bug

Conversation

@nothingmuch
Copy link
Collaborator

@nothingmuch nothingmuch commented Mar 12, 2025

The v1_to_v2 test checks the v2 receiver's polling behavior, and the directory's backwards compatible handling of that.

However, as the following diff demonstrates when applied, it's actually the first request, the one which receives a 503 response whose data makes it to the receiver, and the 202 status check in the test never triggers even when that initial sender's proposal is withheld to force the directory to respond with 202, instead triggering .expect("proposal should exist"):

diff --git a/payjoin/tests/integration.rs b/payjoin/tests/integration.rs
index c500af4..3827b45 100644
--- a/payjoin/tests/integration.rs
+++ b/payjoin/tests/integration.rs
@@ -469,14 +469,14 @@ mod integration {
                             false,
                         )?
                         .extract_v1()?;
-                log::info!("send fallback v1 to offline receiver fail");
-                let res = agent
-                    .post(url.clone())
-                    .header("Content-Type", content_type)
-                    .body(body.clone())
-                    .send()
-                    .await;
-                assert!(res?.status() == StatusCode::SERVICE_UNAVAILABLE);
+                // log::info!("send fallback v1 to offline receiver fail");
+                // let res = agent
+                //     .post(url.clone())
+                //     .header("Content-Type", content_type)
+                //     .body(body.clone())
+                //     .send()
+                //     .await;
+                // assert!(res?.status() == StatusCode::SERVICE_UNAVAILABLE);

                 // **********************
                 // Inside the Receiver:
@@ -497,6 +497,7 @@ mod integration {
                                 "No response yet for POST payjoin request, retrying some seconds"
                             );
                             tokio::time::sleep(std::time::Duration::from_secs(1)).await;
+                            panic!("not expecting 202");
                         } else {
                             log::error!("Unexpected response status: {}", response.status());
                             panic!("Unexpected response status: {}", response.status())
@@ -519,6 +520,10 @@ mod integration {
                     Ok::<_, BoxSendSyncError>(())
                 });

+                // test services configures a timeout of 2 seconds for the
+                // directory before it returns 202 status responses
+                tokio::time::sleep(std::time::Duration::from_secs(3)).await;
+
                 // **********************
                 // send fallback v1 to online receiver
                 log::info!("send fallback v1 to online receiver should succeed");

When a v2 receiver polls expecting a 200 or 202 status response, that
status code is associated with the OHTTP encapsulated response, and is
therefore handled in the process_res method and detected implicitly via
the empty body branch.

The response status for OHTTP gateway requests will always be 200
regardless of what the internal request's status is.
@coveralls
Copy link
Collaborator

coveralls commented Mar 12, 2025

Pull Request Test Coverage Report for Build 13818601223

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 79.738%

Totals Coverage Status
Change from base Build 13792137471: 0.04%
Covered Lines: 4569
Relevant Lines: 5730

💛 - Coveralls

Copy link
Contributor

@DanGould DanGould 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. This must have been written before process_res handled OHTTP properly and been missed somehow.

ACK 1bef64b

Curious about the delay between response processing and request, but the curiosity doesn't necessarily need to be addressed or otherwise block progress.

Copy link
Contributor

@DanGould DanGould left a comment

Choose a reason for hiding this comment

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

ACK 0f7b9e5

@nothingmuch did you re-read the original PR description?

@nothingmuch nothingmuch merged commit 67cb218 into payjoin:master Mar 12, 2025
7 checks passed
@nothingmuch nothingmuch deleted the v1-to-v2-test-202-bug branch March 12, 2025 19:57
@nothingmuch nothingmuch restored the v1-to-v2-test-202-bug branch March 12, 2025 20:15
@nothingmuch nothingmuch deleted the v1-to-v2-test-202-bug branch March 12, 2025 21:15
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