Skip to content

Fix lightning-persister tests for upcoming rustc changes #1033

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

Merged
merged 2 commits into from
Aug 3, 2021

Conversation

TheBlueMatt
Copy link
Collaborator

Upcoming versions of rustc will break existing code (:scream:), so we need to tweak two tests in lightning-persister to work around this. This should fix tests on rustc-beta.

This should catch any platform-specific behavior changes in rustc
before they land in stable.
@codecov
Copy link

codecov bot commented Aug 2, 2021

Codecov Report

Merging #1033 (8490944) into main (bee9a1e) will increase coverage by 0.00%.
The diff coverage is 83.33%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1033   +/-   ##
=======================================
  Coverage   90.80%   90.81%           
=======================================
  Files          60       60           
  Lines       31460    31463    +3     
=======================================
+ Hits        28568    28573    +5     
+ Misses       2892     2890    -2     
Impacted Files Coverage Δ
lightning-block-sync/src/http.rs 93.51% <75.00%> (-0.19%) ⬇️
lightning-persister/src/util.rs 95.77% <100.00%> (ø)
lightning/src/ln/functional_tests.rs 97.36% <0.00%> (+0.04%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bee9a1e...8490944. Read the comment docs.

Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

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

Looks like http::client_tests::connect_to_unresolvable_host has some platform-specific errors. 😞

@@ -135,7 +135,7 @@ mod tests {
// Create the channel data file and make it a directory.
fs::create_dir_all(get_full_filepath(path.clone(), filename.to_string())).unwrap();
match write_to_file(path.clone(), filename.to_string(), &test_writeable) {
Err(e) => assert_eq!(e.kind(), io::ErrorKind::Other),
Err(e) => assert_eq!(e.raw_os_error(), Some(libc::EISDIR)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a TODO to switch back to kind once possible. Though I guess that is a long way out. 😕

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, that's gonna require at least rustc-now, so I guess in at least two years per the rust-bitcoin MSRV policy, assuming distros upgrade. I think this is fine, in any case, at least it won't break.

@@ -636,7 +636,7 @@ pub(crate) mod client_tests {
#[test]
fn connect_to_unresolvable_host() {
match HttpClient::connect(("example.invalid", 80)) {
Err(e) => assert_eq!(e.kind(), std::io::ErrorKind::Other),
Err(_) => { /* rust libstd currently doesn't have a specific error for Host Not Found for us to match against */ },
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on this patch or similar:

diff --git a/lightning-block-sync/src/http.rs b/lightning-block-sync/src/http.rs
index 1f30bea1..93f7bafb 100644
--- a/lightning-block-sync/src/http.rs
+++ b/lightning-block-sync/src/http.rs
@@ -636,7 +636,9 @@ pub(crate) mod client_tests {
        #[test]
        fn connect_to_unresolvable_host() {
                match HttpClient::connect(("example.invalid", 80)) {
-                       Err(_) => { /* rust libstd currently doesn't have a specific error for Host Not Found for us to match against */ },
+                       Err(e) => {
+                               assert_eq!(e.to_string(), "failed to lookup address information: Name or service not known");
+                       },
                        Ok(_) => panic!("Expected error"),
                }
        }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. I went with e.to_string().contains("Name or service not known") as I'm not 100% sure to_string is guaranteed to never change, either.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Turns out its not cross-platform. I think failed to lookup address information will be, for now, though.

@TheBlueMatt TheBlueMatt force-pushed the 2021-07-fix-beta branch 2 times, most recently from 3b328ee to 9d10637 Compare August 2, 2021 18:16
std::io::ErrorKind is a `#[non_exhaustive]` enum as more specific
error types are to be added in the future. It was unclear in the
docs until very recently, however, that this is to be done by
re-defining `ErrorKind::Other` errors to new enum variants. Thus,
our tests which check explicitly for `ErrorKind::Other` as a
result of trying to access a directory as a file were incorrect.
Sadly, these generated no meaningful feedback from rustc at all,
except that they're suddenly failing in rustc beta!

After some back-and-forth, it seems rustc is moving forward
breaking existing code in future versions, so we move to the
"correct" check here, which is to check the raw IO error.

See rust-lang/rust#86442 and rust-lang/rust#85746 for more info.
@TheBlueMatt TheBlueMatt merged commit 75f77a5 into lightningdevkit:main Aug 3, 2021
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