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

chore: Refactor unit tests #2294

Merged
merged 20 commits into from May 8, 2019
Merged

Conversation

bartlomieju
Copy link
Member

This PR tries to resolve issue #2103.

In the first pass I've changed the behavior of Python script to run unit tests with every possible combination of permissions. This ensures that no test is skipped but requires to spawn separate Deno process for each combination even if there are no tests to run. This approach is really suboptimal.

My next step will be to first run a process to discover all tests and establish which perm combinations are used in test cases and then spawn new processes only for those combinations.

By the way, I think that this combination technique might be useful for users as well. Maybe we should consider implementing it in standard library? Eg. in deno-postgres I need to run tests once with --allow-env flag and second time without it, I'd be neat if this was built in without need to port this behavior.

CC @ry

js/test_util.ts Outdated Show resolved Hide resolved
@bartlomieju
Copy link
Member Author

bartlomieju commented May 5, 2019

Alright, I got functionality from 1st comment working. It still needs cleanup but most of logic is already there.

EDIT: With removal of testing.setFilter it seems that tests should be run with --no-prompt now

raise AssertionError("Bad js/unit_test.ts output")
if expected != actual:
print "expected", expected, "actual", actual
raise AssertionError("expected tests did not equal actual")
Copy link
Member

Choose a reason for hiding this comment

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

This logic should be ported over to the runner too

Copy link
Member Author

Choose a reason for hiding this comment

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

The thing is: up till now if one of tests failed remaining tests for other permissions were not run. I think we can safely spawn subprocesses for each permissions combination and return failure if any of them failed. That way all tests will always run, what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

That sounds fine. But for each set of permissions there is a summary line printed. For example:

Running tests for: --allow-write --allow-run
running 1 tests
test runWithCwdIsAsync ... ok

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

The js/unit_tests_runner.ts needs to parse the first line (to determine how many tests there are) and then also parse the last line to check that passed matches. If we don't have this feature, it's possible for Deno to silently crash with exit code 0 and the tests all pass.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, I'll add it

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, so I've ported it to TS, but the thing is... There is no line-per-line output of unit tests ATM because there's no available lines helper. I didn't want to copy over chunks implemented by @kevinkassimo from xeval.ts and there's no way to use it, because that file uses extensionless imports.

Copy link
Member Author

Choose a reason for hiding this comment

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

CC @ry

Copy link
Member

Choose a reason for hiding this comment

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

Just copy it over add a todo ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay I tried... It's not really possible since chunk from xeval.ts uses import from js/buffer.ts so again there's conflict because of extensionless imports. I'm gonna leave it as is for now...

js/unit_test_runner.ts Outdated Show resolved Hide resolved
js/unit_test_runner.ts Outdated Show resolved Hide resolved
@bartlomieju
Copy link
Member Author

I've also added short summary at the end of run, because it's easy to miss if something went wrong at the beginning:

$ ./tools/unit_tests.py target/debug/deno

...

Summary for <no permissions>
test result: ok. 216 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Summary for --allow-read
test result: FAILED. 33 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

Summary for --allow-net
test result: ok. 18 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Summary for --allow-read --allow-write
test result: ok. 48 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Summary for --allow-write
test result: ok. 15 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Summary for --allow-env
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Summary for --allow-run
test result: ok. 14 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Summary for --allow-write --allow-run
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Summary for --allow-high-precision
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Unit tests failed

What do you think?

@ry
Copy link
Member

ry commented May 6, 2019

I'm slightly concerned around running many processes in parallel on windows. @piscisaureus can you please check this branch on windows works for you:

# Run http server in the brackground first
./tools/http_server.py &  

./target/debug/deno run -A js/unit_test_runner.ts

@ry
Copy link
Member

ry commented May 6, 2019

Otherwise looks great!

tools/unit_tests.py Outdated Show resolved Hide resolved
@bartlomieju
Copy link
Member Author

bartlomieju commented May 6, 2019

I'm slightly concerned around running many processes in parallel on windows.

Processes are run serially. Also command you showed is unnecessary, you can just run tools/unit_tests.py

There's also one more thing to solve, please see this comment

Otherwise looks great!

Thanks!

@piscisaureus
Copy link
Member

I get this (freshly rebuilt):

D:\deno2>python tools\unit_tests.py target\release\deno
Deno test server http://localhost:4545/
redirect server http://localhost:4546/ -> http://localhost:4545/
redirect server http://localhost:4547/ -> http://localhost:4545/
redirect server http://localhost:4548/ -> http://localhost:4546/
Compiling file:///D:/deno2/js/unit_test_runner.ts
Compiling file:///D:/deno2/js/test_util.ts
D:/deno2/js/test_util.ts:225:66 - error TS1064: The return type of an async function or method must be the global Promise<T> type.

225 testPerm({ read: true }, async function parsingUnitTestOutput(): void {
                                                                     ~~~~

@bartlomieju
Copy link
Member Author

@piscisaureus I've just pushed a fix

@piscisaureus
Copy link
Member

D:\deno2>python tools\unit_tests.py target\release\deno
Deno test server http://localhost:4545/
redirect server http://localhost:4546/ -> http://localhost:4545/
redirect server http://localhost:4547/ -> http://localhost:4545/
redirect server http://localhost:4548/ -> http://localhost:4546/
Compiling file:///D:/deno2/js/unit_test_runner.ts
<...snip...>
Compiling file:///D:/deno2/js/deps/https/deno.land/std/testing/format.ts
Discovered permission combinations for tests: 9
        <no permissions>
        --allow-read
        --allow-net
        --allow-read --allow-write
        --allow-write
        --allow-env
        --allow-run
        --allow-write --allow-run
        --allow-high-precision
Running tests for: <no permissions>
Assertion failedHello worldHello world
<...process hangs...>

@bartlomieju
Copy link
Member Author

@piscisaureus would you be willing to help out with debugging? Unfortunately I don't have access to Windows machine

stdout: "piped"
});

await p.status();
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes the windows env hangs.
Commenting it make everything works as we wait for p.output() after. Maybe this is a bug in the Deno.run ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@zekth kudos for help 🙏 I'll update PR in the evening

Copy link
Contributor

Choose a reason for hiding this comment

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

@zekth Can you create an issue/test case for the Deno.run error? (assuming it's a bug!)

Copy link
Contributor

Choose a reason for hiding this comment

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

@hayd spent 1 hour trying to reproduce this, no luck for the moment. Raising an issue to track it.

@zekth
Copy link
Contributor

zekth commented May 8, 2019

Additionnal note:
with disabling await p.status() the tests passe. BUT there is a strange behavior, if you check the ouput of my tests: https://gist.github.com/zekth/8af9973a94c1fd541869e6ab901f00d1
there is a difference between the mac os one for example : https://travis-ci.com/denoland/deno/jobs/198071750

TLDR: there is no console test shown in my logs. But we have the same output : test result: ok. 216 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

As i mentionned i've supposed a problem in the Deno.run(). Tried the example of the manual : https://deno.land/manual.html#runsubprocess with the check of process.status(). And it works. Seems like the exception in the blob test may throw something not interpreted the same way on all envs.

@bartlomieju
Copy link
Member Author

bartlomieju commented May 8, 2019

Okay so removing await p.status() resolved problem on Windows. Not really sure what was the problem, it will need some investigating.

@zekth
Copy link
Contributor

zekth commented May 8, 2019

Okay so removing await p.status() resolved problem on Windows. Not really sure what was the problem, it will need some investigating.

As this PR may land before resolving this behaviour it is revelant for me to raise an issue for this to track before having some other problems like this on windows


let result = 0;

if (!actual && !expected) {
Copy link
Member

Choose a reason for hiding this comment

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

This is a little difficult to read. I presume this is covering the case where actual and expected are both undefined? It could use a comment.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

This looks great! Thanks for seeing this through.

@ry ry merged commit ac8c6fe into denoland:master May 8, 2019
@bartlomieju bartlomieju deleted the chore_refactor_unit_tests branch May 19, 2019 20:32
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

5 participants