Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Rework cmd tests #1062

Merged
merged 1 commit into from
Sep 30, 2018
Merged

Rework cmd tests #1062

merged 1 commit into from
Sep 30, 2018

Conversation

alexheretic
Copy link
Member

@alexheretic alexheretic commented Sep 21, 2018

  • Rewrite all tests/tests.rs "cmd" tests
  • cargo update
  • cmd test wait-for-rls-stdout timeout reduced 300 -> 30

The cmd tests aren't good enough because they don't fail very usefully. They either work or block for 300 seconds then say nothing. For example the build is currently failing in master, but can anyone see why?

The new code has

  • Explicit timeouts for any blocking calls, meaning it's easy to see where we wait for stdout.
  • More accurate dynamic json assertions.
    assert_eq!(json["method"], "window/progress");
    assert_eq!(json["params"]["title"], "Indexing");
  • Removed all but one test checking window/progress messages.
  • Removed outer timeout/closure which obfuscates test panics & adds complexity.

The RlsHandle now uses a thread to eagerly read stdout, and eprints that stdout when an assertion fails. This stdout allows us to debug the tests when they fail. To see the improvement here is the failure output of the tests with this change:

running 4 tests
test cmd_test_infer_bin ... FAILED
test cmd_test_complete_self_crate_name ... ok
test cmd_test_simple_workspace ... ok
test cmd_changing_workspace_lib_retains_bin_diagnostics ... ok

failures:

---- cmd_test_infer_bin stdout ----
thread 'cmd_test_infer_bin' panicked at 'assertion failed: `(left == right)`
  left: `String("window/showMessage")`,
 right: `"textDocument/publishDiagnostics"`', tests/tests.rs:58:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
---rls-stdout---
Content-Length: 607

{"jsonrpc":"2.0","id":0,"result":{"capabilities":{"textDocumentSync":2,"hoverProvider":true,"completionProvider":{"resolveProvider":true,"triggerCharacters":[".",":"]},"definitionProvider":true,"implementationProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"workspaceSymbolProvider":true,"codeActionProvider":true,"codeLensProvider":{"resolveProvider":false},"documentFormattingProvider":true,"documentRangeFormattingProvider":false,"renameProvider":true,"executeCommandProvider":{"commands":["rls.applySuggestion-29146","rls.deglobImports-29146"]}}}}Content-Length: 92

{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_1","title":"Building"}}Content-Length: 104

{"jsonrpc":"2.0","method":"window/progress","params":{"done":true,"id":"progress_1","title":"Building"}}Content-Length: 92

{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_0","title":"Indexing"}}Content-Length: 157

{"jsonrpc":"2.0","method":"window/showMessage","params":{"message":"Cargo failed: failed to parse manifest at `/home/alex/project/rls/Cargo.toml`","type":1}}Content-Length: 104

{"jsonrpc":"2.0","method":"window/progress","params":{"done":true,"id":"progress_0","title":"Indexing"}}
---------------


failures:
    cmd_test_infer_bin

test result: FAILED. 3 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

Once you have this output it's fairly easy to see Cargo failed: failed to parse manifest at /home/alex/project/rls/Cargo.toml. The recent update (#1058) to the main Cargo.toml is was interfering with the cmd tests.

And all this with ~100 lines net removed :)

@Xanewok
Copy link
Member

Xanewok commented Sep 22, 2018

I've been meaning to tackle the recent infer_bin failure myself, thank you! It's a lot better to see what's causing the actual failure. Could you rebase after the #1063 merge, please?

@Xanewok
Copy link
Member

Xanewok commented Sep 22, 2018

cc @spacekookie who also wanted to tackle the integration "cmd" tests and do more structural checking

@alexheretic alexheretic force-pushed the alex-cmd-tests branch 3 times, most recently from 31b8ef4 to 7edd6d2 Compare September 23, 2018 12:15
@Xanewok
Copy link
Member

Xanewok commented Sep 28, 2018

Hey @alexheretic, I'm sorry for the churn - could you please rebase it again and only include the testing changes (it seems that cargo update was done recently already) to mitigate potential conflicts? Thanks! I'd love to land this and include more tests.

@alexheretic
Copy link
Member Author

np

@Xanewok
Copy link
Member

Xanewok commented Sep 30, 2018

Thanks once again!

bors r+

bors-voyager bot added a commit that referenced this pull request Sep 30, 2018
1062: Rework cmd tests r=Xanewok a=alexheretic

* Rewrite all _tests/tests.rs_ "cmd" tests
* <s>cargo update</s>
* cmd test wait-for-rls-stdout timeout reduced 300 -> 30

The cmd tests aren't good enough because they don't fail very usefully. They either work or block for 300 seconds then say nothing. For example the build is currently failing in master, but can anyone see why?

The new code has
* Explicit timeouts for any blocking calls, meaning it's easy to see where we wait for stdout.
* More accurate dynamic json assertions. 
   ```rust
   assert_eq!(json["method"], "window/progress");
   assert_eq!(json["params"]["title"], "Indexing");
   ```
* Removed all but one test checking _window/progress_ messages.
* Removed outer timeout/closure which obfuscates test panics & adds complexity.

The `RlsHandle` now uses a thread to eagerly read stdout, and eprints that stdout when an assertion fails. This stdout allows us to debug the tests when they fail. To see the improvement here is the failure output of the tests with this change:

```
running 4 tests
test cmd_test_infer_bin ... FAILED
test cmd_test_complete_self_crate_name ... ok
test cmd_test_simple_workspace ... ok
test cmd_changing_workspace_lib_retains_bin_diagnostics ... ok

failures:

---- cmd_test_infer_bin stdout ----
thread 'cmd_test_infer_bin' panicked at 'assertion failed: `(left == right)`
  left: `String("window/showMessage")`,
 right: `"textDocument/publishDiagnostics"`', tests/tests.rs:58:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
---rls-stdout---
Content-Length: 607

{"jsonrpc":"2.0","id":0,"result":{"capabilities":{"textDocumentSync":2,"hoverProvider":true,"completionProvider":{"resolveProvider":true,"triggerCharacters":[".",":"]},"definitionProvider":true,"implementationProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"workspaceSymbolProvider":true,"codeActionProvider":true,"codeLensProvider":{"resolveProvider":false},"documentFormattingProvider":true,"documentRangeFormattingProvider":false,"renameProvider":true,"executeCommandProvider":{"commands":["rls.applySuggestion-29146","rls.deglobImports-29146"]}}}}Content-Length: 92

{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_1","title":"Building"}}Content-Length: 104

{"jsonrpc":"2.0","method":"window/progress","params":{"done":true,"id":"progress_1","title":"Building"}}Content-Length: 92

{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_0","title":"Indexing"}}Content-Length: 157

{"jsonrpc":"2.0","method":"window/showMessage","params":{"message":"Cargo failed: failed to parse manifest at `/home/alex/project/rls/Cargo.toml`","type":1}}Content-Length: 104

{"jsonrpc":"2.0","method":"window/progress","params":{"done":true,"id":"progress_0","title":"Indexing"}}
---------------


failures:
    cmd_test_infer_bin

test result: FAILED. 3 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
```

Once you have this output it's fairly easy to see **Cargo failed: failed to parse manifest at `/home/alex/project/rls/Cargo.toml`**. The recent update (#1058) to the main Cargo.toml <s>is</s> was interfering with the cmd tests.

And all this with ~100 lines net removed :)

Co-authored-by: Alex Butler <[email protected]>
@bors-voyager
Copy link
Contributor

bors-voyager bot commented Sep 30, 2018

@bors-voyager bors-voyager bot merged commit e13b694 into rust-lang:master Sep 30, 2018
@alexheretic alexheretic deleted the alex-cmd-tests branch September 30, 2018 22:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants