Skip to content

run round_trip's assertions in separate threads #53

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 11 commits into from
Jun 5, 2020

Conversation

p-alik
Copy link
Contributor

@p-alik p-alik commented May 24, 2020

This approach ensures the test reachs killing of client's thread.
This commit aims to solve issue #50

Copy link
Owner

@weiznich weiznich left a comment

Choose a reason for hiding this comment

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

I've left some small suggestions for improvements, otherwise this looks fine. Thanks for working on this 👍


child.kill().unwrap();
child.wait().unwrap();
match handler.join() {
Copy link
Owner

Choose a reason for hiding this comment

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

As this is test code it's totally fine to just do a dbg!(handler.join()) here. Cargo does not print output from succeeding tests by default.

So something like dbg!(handler.join()).is_ok() should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

375c03a uses a closure for two Err(..)'s inside request_test. Do you still see demand of amendment?

@@ -2,6 +2,7 @@ use crate::database::InferConnection;
use crate::infer_schema_internals::*;
use std::error::Error;
use std::io::Write;
use std::thread;
Copy link
Owner

Choose a reason for hiding this comment

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

Seems like this import is not needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, the import is removed in 375c03a

@p-alik
Copy link
Contributor Author

p-alik commented May 26, 2020

It looks like I've to improve settings of local rustfmt because it produces the style, which fails in CI. Could you provide any advice for proper setup of rustfmt?

@p-alik p-alik force-pushed the issue-50 branch 2 times, most recently from 29ef069 to 98d7d0d Compare May 26, 2020 18:37
Copy link
Owner

@weiznich weiznich left a comment

Choose a reason for hiding this comment

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

Generally I'm fine with those changes. I've added some small stylistic suggestions how to improve the implementation.

(Sorry for taking some time to do the review, but real life is currently quite time demanding)

@@ -476,6 +476,16 @@ impl<'a> Display for GraphqlInsertable<'a> {
let mut out = PadAdapter::new(f);
writeln!(out)?;
for c in self.table.column_data.iter().filter(|c| !c.has_default) {
let is_pk = self
Copy link
Owner

Choose a reason for hiding this comment

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

I think it would be better to add this as part of the filter expression in the line above?

(I'm not sure why this is even missing. I remember writing similar code there 🙈 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 6c70d55

}
}

fn request_test(client: &reqwest::Client, listen_url: &str, body: &'static str) -> bool {
Copy link
Owner

Choose a reason for hiding this comment

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

I would prefer to just return a result here and bubble up any potential errors. Then we could just do a t1.is_err() instead of !t1 in the test above. I think this would make the code much clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed!


match r {
Ok(mut r) => {
let builder = std::thread::Builder::new().name("round_trip".into());
Copy link
Owner

Choose a reason for hiding this comment

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

It's better to use std::panic::catch_unwind() instead here in my opinion. Also this would allow us to just bubble up the "error" in the fail case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

4152b3d contains std::panic::catch_unwind based approach

@p-alik
Copy link
Contributor Author

p-alik commented May 29, 2020

It looks like I've to improve settings of local rustfmt because it produces the style, which fails in CI. Could you provide any advice for proper setup of rustfmt?

Is max_width defintion in my rustfmt.toml to blame?

$ cat ~/.config/rustfmt/rustfmt.toml 
max_width=80
edition="2018"

an alternative to previous thread based approach
@p-alik
Copy link
Contributor Author

p-alik commented May 29, 2020

Is max_width defintion in my rustfmt.toml to blame?

It was due to default value

@p-alik
Copy link
Contributor Author

p-alik commented May 29, 2020

I can't reproduce sqlite test failure locally. I'm still getting the old once for reason Int4 vs Integer.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Snapshot Differences ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Snapshot file: wundergraph_cli/src/print_schema/snapshots/tests__infer_schema.snap
Snapshot: infer_schema
Source: wundergraph_cli/src/print_schema/mod.rs:154
-old snapshot
+new results
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
&s
────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    2     2 │ use wundergraph::scalar::WundergraphScalarValue;
    3     3 │ use wundergraph::WundergraphEntity;
    4     4 │
    5     5 │ table! {
    6       │-    infer_test.comments (id) {
    7       │-        id -> Int4,
    8       │-        post -> Nullable<Int4>,
    9       │-        commenter -> Nullable<Int4>,
          6 │+    comments (id) {
          7 │+        id -> Integer,
          8 │+        post -> Nullable<Integer>,
          9 │+        commenter -> Nullable<Integer>,
   10    10 │         content -> Text,
   11    11 │     }
   12    12 │ }
   13    13 │

@weiznich
Copy link
Owner

Thanks for the changes:+1:

can't reproduce sqlite test failure locally. I'm still getting the old once for reason Int4 vs Integer.

I will try to have a look at the weekend/beginning of the next week

It was due to default value

Yes that makes sense. Wundergraph is basically just using the default configs for rustfmt here. I wonder if it could be meaningful to have a rustfmt.toml with default configs in the repo 🤔

Copy link
Contributor Author

@p-alik p-alik left a comment

Choose a reason for hiding this comment

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

thank you!

Alexei Pastuchov and others added 2 commits June 4, 2020 20:41
+little amemdment in the content
@p-alik
Copy link
Contributor Author

p-alik commented Jun 4, 2020

I can't reproduce the new test failure locally.

The only failure I get for
DATABASE_URL=wundergraph_cli.db cargo test --manifest-path wundergraph_cli/Cargo.toml --features sqlite --no-default-features -- --nocapture
is
thread 'print_schema::tests::round_trip' panicked at 'called Result::unwrap()on anErr value: DatabaseError(__Unknown, "database is locked")', wundergraph_cli/src/print_schema/mod.rs:141:21.

But cargo test runs error-free for only round_trip test.

@weiznich
Copy link
Owner

weiznich commented Jun 4, 2020

The sqlite backend does not really support running tests in parallel yet, therefore tests need to be run with RUST_THREADS=1 or --test-threads=1 as argument.
If just pushed a commit that should fix the CI, but I'm not sure about that, so let's just wait for the results.

@p-alik
Copy link
Contributor Author

p-alik commented Jun 5, 2020

Single threaded cargo test runs error-free for me yet.

@weiznich weiznich merged commit ffbb883 into weiznich:master Jun 5, 2020
@p-alik p-alik deleted the issue-50 branch June 5, 2020 11:19
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.

2 participants