Skip to content

Commit 3806525

Browse files
author
John Messerly
committed
fixes #292, report async_helper test failures
[email protected] Review URL: https://codereview.chromium.org/1289673007 .
1 parent 8f9c38b commit 3806525

File tree

6 files changed

+329
-278
lines changed

6 files changed

+329
-278
lines changed

pkg/dev_compiler/test/browser/language_tests.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
let _isolate_helper = dart_library.import('dart/_isolate_helper');
99
_isolate_helper.startRootIsolate(function() {}, []);
1010

11+
let async_helper = dart_library.import('async_helper/async_helper');
12+
1113
function dartLanguageTests(tests) {
1214
for (const name of tests) {
13-
test(name, () => {
14-
console.debug('Running language test: ' + name);
15+
test(name, (done) => {
16+
async_helper.asyncTestInitialize(done);
17+
console.debug('Running language test: ' + name);
1518
dart_library.import('language/' + name).main();
19+
if (!async_helper.asyncTestStarted) done();
1620
});
1721
}
1822
}
@@ -48,7 +52,8 @@
4852
'async_rethrow_test',
4953
// TODO(jmesserly): fix errors
5054
// 'async_return_types_test',
51-
'async_switch_test',
55+
// TODO(jmesserly): https://github.com/dart-lang/dev_compiler/issues/294
56+
// 'async_switch_test',
5257
'async_test',
5358
'async_this_bound_test',
5459
'async_throw_in_catch_test'
@@ -63,7 +68,8 @@
6368
//'async_star_cancel_and_throw_in_finally_test',
6469
'async_star_regression_23116_test',
6570
'asyncstar_concat_test',
66-
'asyncstar_throw_in_catch_test',
71+
// TODO(jmesserly): https://github.com/dart-lang/dev_compiler/issues/294
72+
// 'asyncstar_throw_in_catch_test',
6773
'asyncstar_yield_test',
6874
'asyncstar_yieldstar_test'
6975
]);

pkg/dev_compiler/test/codegen/async_helper.dart

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,44 @@
2323
2424
library async_helper;
2525

26-
// TODO(kustermann): This is problematic because we rely on a working
27-
// 'dart:isolate' (i.e. it is in particular problematic with dart2js).
28-
// It would be nice if we could use a different mechanism for different
29-
// runtimes.
30-
import 'dart:isolate';
31-
3226
bool _initialized = false;
33-
ReceivePort _port = null;
27+
28+
typedef void _Action0();
29+
_Action0 _onAsyncEnd;
30+
3431
int _asyncLevel = 0;
3532

3633
Exception _buildException(String msg) {
3734
return new Exception('Fatal: $msg. This is most likely a bug in your test.');
3835
}
3936

37+
/// Implementation method called from language_tests.js.
38+
/// Registers the callback that will be used complete the test.
39+
void asyncTestInitialize(_Action0 callback) {
40+
_asyncLevel = 0;
41+
_initialized = false;
42+
_onAsyncEnd = callback;
43+
}
44+
45+
/// Implementation method called from language_tests.js.
46+
/// Returns true if an asyncTest was started.
47+
bool get asyncTestStarted => _initialized;
48+
4049
/// Call this method before an asynchronous test is created.
4150
void asyncStart() {
4251
if (_initialized && _asyncLevel == 0) {
4352
throw _buildException('asyncStart() was called even though we are done '
4453
'with testing.');
4554
}
4655
if (!_initialized) {
56+
if (_onAsyncEnd == null) {
57+
throw _buildException(
58+
'asyncStart() was called before asyncTestInitialize()');
59+
}
60+
4761
print('unittest-suite-wait-for-done');
4862
_initialized = true;
49-
_port = new ReceivePort();
63+
5064
}
5165
_asyncLevel++;
5266
}
@@ -63,8 +77,9 @@ void asyncEnd() {
6377
}
6478
_asyncLevel--;
6579
if (_asyncLevel == 0) {
66-
_port.close();
67-
_port = null;
80+
var callback = _onAsyncEnd;
81+
_onAsyncEnd = null;
82+
callback();
6883
print('unittest-suite-success');
6984
}
7085
}

pkg/dev_compiler/test/codegen/expect/async_helper.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
dart_library.library('async_helper', null, /* Imports */[
22
"dart_runtime/dart",
3-
'dart/core',
4-
'dart/isolate'
3+
'dart/core'
54
], /* Lazy imports */[
6-
], function(exports, dart, core, isolate) {
5+
], function(exports, dart, core) {
76
'use strict';
87
let dartx = dart.dartx;
98
exports._initialized = false;
10-
exports._port = null;
9+
let _Action0 = dart.typedef('_Action0', () => dart.functionType(dart.void, []));
10+
exports._onAsyncEnd = null;
1111
exports._asyncLevel = 0;
1212
function _buildException(msg) {
1313
return core.Exception.new(`Fatal: ${msg}. This is most likely a bug in your test.`);
1414
}
1515
dart.fn(_buildException, core.Exception, [core.String]);
16+
function asyncTestInitialize(callback) {
17+
exports._asyncLevel = 0;
18+
exports._initialized = false;
19+
exports._onAsyncEnd = callback;
20+
}
21+
dart.fn(asyncTestInitialize, dart.void, [_Action0]);
22+
dart.copyProperties(exports, {
23+
get asyncTestStarted() {
24+
return exports._initialized;
25+
}
26+
});
1627
function asyncStart() {
1728
if (dart.notNull(exports._initialized) && exports._asyncLevel == 0) {
1829
dart.throw(_buildException('asyncStart() was called even though we are done ' + 'with testing.'));
1930
}
2031
if (!dart.notNull(exports._initialized)) {
32+
if (exports._onAsyncEnd == null) {
33+
dart.throw(_buildException('asyncStart() was called before asyncTestInitialize()'));
34+
}
2135
core.print('unittest-suite-wait-for-done');
2236
exports._initialized = true;
23-
exports._port = isolate.ReceivePort.new();
2437
}
2538
exports._asyncLevel = dart.notNull(exports._asyncLevel) + 1;
2639
}
@@ -35,8 +48,9 @@ dart_library.library('async_helper', null, /* Imports */[
3548
}
3649
exports._asyncLevel = dart.notNull(exports._asyncLevel) - 1;
3750
if (exports._asyncLevel == 0) {
38-
exports._port.close();
39-
exports._port = null;
51+
let callback = exports._onAsyncEnd;
52+
exports._onAsyncEnd = null;
53+
callback();
4054
core.print('unittest-suite-success');
4155
}
4256
}
@@ -51,6 +65,7 @@ dart_library.library('async_helper', null, /* Imports */[
5165
}
5266
dart.fn(asyncTest, dart.void, [dart.functionType(dart.dynamic, [])]);
5367
// Exports:
68+
exports.asyncTestInitialize = asyncTestInitialize;
5469
exports.asyncStart = asyncStart;
5570
exports.asyncEnd = asyncEnd;
5671
exports.asyncSuccess = asyncSuccess;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// Messages from compiling async_helper.dart
2-
info: [DynamicInvoke] f().then(asyncSuccess) requires dynamic invoke (test/codegen/async_helper.dart, line 93, col 3)
2+
info: [DynamicInvoke] f().then(asyncSuccess) requires dynamic invoke (test/codegen/async_helper.dart, line 108, col 3)

pkg/dev_compiler/test/codegen/expect/async_helper/async_helper.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
dart_library.library('async_helper/async_helper', null, /* Imports */[
22
"dart_runtime/dart",
3-
'dart/core',
4-
'dart/isolate'
3+
'dart/core'
54
], /* Lazy imports */[
6-
], function(exports, dart, core, isolate) {
5+
], function(exports, dart, core) {
76
'use strict';
87
let dartx = dart.dartx;
98
exports._initialized = false;
10-
exports._port = null;
9+
let _Action0 = dart.typedef('_Action0', () => dart.functionType(dart.void, []));
10+
exports._onAsyncEnd = null;
1111
exports._asyncLevel = 0;
1212
function _buildException(msg) {
1313
return core.Exception.new(`Fatal: ${msg}. This is most likely a bug in your test.`);
1414
}
1515
dart.fn(_buildException, core.Exception, [core.String]);
16+
function asyncTestInitialize(callback) {
17+
exports._asyncLevel = 0;
18+
exports._initialized = false;
19+
exports._onAsyncEnd = callback;
20+
}
21+
dart.fn(asyncTestInitialize, dart.void, [_Action0]);
22+
dart.copyProperties(exports, {
23+
get asyncTestStarted() {
24+
return exports._initialized;
25+
}
26+
});
1627
function asyncStart() {
1728
if (dart.notNull(exports._initialized) && exports._asyncLevel == 0) {
1829
dart.throw(_buildException('asyncStart() was called even though we are done ' + 'with testing.'));
1930
}
2031
if (!dart.notNull(exports._initialized)) {
32+
if (exports._onAsyncEnd == null) {
33+
dart.throw(_buildException('asyncStart() was called before asyncTestInitialize()'));
34+
}
2135
core.print('unittest-suite-wait-for-done');
2236
exports._initialized = true;
23-
exports._port = isolate.ReceivePort.new();
2437
}
2538
exports._asyncLevel = dart.notNull(exports._asyncLevel) + 1;
2639
}
@@ -35,8 +48,9 @@ dart_library.library('async_helper/async_helper', null, /* Imports */[
3548
}
3649
exports._asyncLevel = dart.notNull(exports._asyncLevel) - 1;
3750
if (exports._asyncLevel == 0) {
38-
exports._port.close();
39-
exports._port = null;
51+
let callback = exports._onAsyncEnd;
52+
exports._onAsyncEnd = null;
53+
callback();
4054
core.print('unittest-suite-success');
4155
}
4256
}
@@ -51,6 +65,7 @@ dart_library.library('async_helper/async_helper', null, /* Imports */[
5165
}
5266
dart.fn(asyncTest, dart.void, [dart.functionType(dart.dynamic, [])]);
5367
// Exports:
68+
exports.asyncTestInitialize = asyncTestInitialize;
5469
exports.asyncStart = asyncStart;
5570
exports.asyncEnd = asyncEnd;
5671
exports.asyncSuccess = asyncSuccess;

0 commit comments

Comments
 (0)