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

add assertOps sanitizer in cli/js/ unit tests #4209

Merged
merged 8 commits into from Mar 3, 2020

Conversation

bartlomieju
Copy link
Member

@bartlomieju bartlomieju commented Mar 1, 2020

Follow up to #4161; this PR adds assertOps sanitizer that ensures that test case does not have "leaking" async ops - ie. there are no unresolved promises. Having dangling promises from async ops leads to very strange behaviors in tests that we have experienced multiple times.

Obviously there are quite a few tests in cli/js/ that leak ops :))

cli/js/signal_test.ts Outdated Show resolved Hide resolved
cli/js/signal_test.ts Outdated Show resolved Hide resolved
cli/js/workers_test.ts Outdated Show resolved Hide resolved
cli/js/workers_test.ts Outdated Show resolved Hide resolved
@bartlomieju bartlomieju requested a review from ry March 1, 2020 15:58
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.

Looks fine at first glance but can we do this in two PRs? One that adds the new metrics and then a second that adds the new check?

I'm a little concerned about the signal test being disabled.

Comment on lines 130 to 131
// Defer for a moment to allow interval promise to resolve
await defer(20);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is bad - it was not signal implementation that was leaking ops but interval. Because our internal timer implementation uses promises; after clearing an interval, one actually needs to wait until timer promise resolves. Otherwise that's considered a leak because timers are based on "ops".

Copy link
Member

Choose a reason for hiding this comment

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

Can you add a TODO here explaining the situation? We should adjust the interval implementation to avoid this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added more description and FIXME in cli/js/timers.ts

cli/js/net_test.ts Show resolved Hide resolved
Comment on lines 130 to 131
// Defer for a moment to allow interval promise to resolve
await defer(20);
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a TODO here explaining the situation? We should adjust the interval implementation to avoid this.

cli/js/signal_test.ts Show resolved Hide resolved
postMessage(e.data);
close();
};

onerror = function() {
console.log("called onerror in worker");
return false;
};
Copy link
Member

Choose a reason for hiding this comment

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

I don’t understand why all these console.log statements are being removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not needed and was harder to match output in integration test

fetchingWorker.onmessage = (e): void => {
assert(e.data === "Done!");
promise.resolve();
};

await promise;
});

await Deno.runTests();
Copy link
Member

Choose a reason for hiding this comment

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

Is moving this workers_test related to the assertOps?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, workers are leaking ops at the moment because there is no way to terminate worker (not implemented yet), added FIXME at the top of the file

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.

LGTM - nice work

@bartlomieju bartlomieju merged commit ee452ad into denoland:master Mar 3, 2020
@bartlomieju bartlomieju deleted the op_sanitizer branch March 3, 2020 17:22
dubiousjim added a commit to dubiousjim/deno that referenced this pull request Mar 5, 2020
* denoland/master: (22 commits)
  fix event target tests
  Support async function and EventListenerObject as listeners (denoland#4240)
  Allow BadResource errors to take a custom message (denoland#4251)
  Document TypeScript compiler options (denoland#4241)
  refactor: preliminary cleanup of Deno.runTests() (denoland#4237)
  refactor: cleanup compiler runtimes (denoland#4230)
  Use discord instead of gitter (denoland#4253)
  Remove unnecessary macro from cli/ops/tty.rs (denoland#4254)
  Remove Deno.errors.Other (denoland#4249)
  refactor: rewrite testPerm into unitTest (denoland#4231)
  Migrate internal bundles to System (denoland#4233)
  Fix inlining of lib.dom.iterable.d.ts. (denoland#4242)
  Fix `deno install` file name including extra dot on Windows (denoland#4243)
  assert build success for test plugin (denoland#4223)
  Disable flaky and broken tests (denoland#4239)
  add assertOps sanitizer in cli/js/ unit tests (denoland#4209)
  misc: reduce unnecesarry output in cli/js tests (denoland#4182)
  feat(std/node): add directory classes (denoland#4087)
  Do not convert exceptions to JSON and back (denoland#4214)
  Don't reset exception handle after calling ErrWithV8Handle::get_handle() (denoland#4214)
  ...
mhvsa pushed a commit to mhvsa/deno that referenced this pull request Mar 6, 2020
* add "assertOps" test assertion which makes sure test case
  is not "leaking" ops - ie. after test finishes there are no 
  pending async ops

* apply "assertOps" to all tests in "cli/js/"

* fix numerous tests leaking ops

* document problem with edge case in "clearInterval"
   and "clearTimeout" implementation where they
   may leak async ops

* move "cli/js/worker_test.ts" to "cli/tests/worker_test.ts" and 
  run as integration test; workers leak ops because of missing
  "terminate" implementation
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

2 participants