This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an e2e test using the worker and driver from this package (#7)
- Loading branch information
Showing
7 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:e2e_test/async_worker.dart'; | ||
|
||
Future main() async { | ||
await new ExampleAsyncWorker().run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:e2e_test/sync_worker.dart'; | ||
|
||
void main() { | ||
new ExampleSyncWorker().run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:bazel_worker/bazel_worker.dart'; | ||
|
||
/// Example worker that just returns in its response all the arguments passed | ||
/// separated by newlines. | ||
class ExampleAsyncWorker extends AsyncWorkerLoop { | ||
Future<WorkResponse> performRequest(WorkRequest request) async { | ||
return new WorkResponse() | ||
..exitCode = 0 | ||
..output = request.arguments.join('\n'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:bazel_worker/bazel_worker.dart'; | ||
|
||
/// Example worker that just returns in its response all the arguments passed | ||
/// separated by newlines. | ||
class ExampleSyncWorker extends SyncWorkerLoop { | ||
WorkResponse performRequest(WorkRequest request) { | ||
return new WorkResponse() | ||
..exitCode = 0 | ||
..output = request.arguments.join('\n'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: e2e_test | ||
dependencies: | ||
bazel_worker: | ||
path: ../ | ||
dev_dependencies: | ||
cli_util: ^0.0.1 | ||
path: ^1.4.1 | ||
test: ^0.12.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:bazel_worker/driver.dart'; | ||
import 'package:cli_util/cli_util.dart'; | ||
import 'package:path/path.dart' as p; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
var sdkDir = getSdkDir(); | ||
var dart = p.join(sdkDir.path, 'bin', 'dart'); | ||
runE2eTestForWorker('sync worker', | ||
() => Process.start(dart, [p.join('bin', 'sync_worker.dart')])); | ||
runE2eTestForWorker('async worker', | ||
() => Process.start(dart, [p.join('bin', 'async_worker.dart')])); | ||
} | ||
|
||
void runE2eTestForWorker(String groupName, SpawnWorker spawnWorker) { | ||
BazelWorkerDriver driver; | ||
group(groupName, () { | ||
setUp(() { | ||
driver = new BazelWorkerDriver(spawnWorker); | ||
}); | ||
|
||
tearDown(() async { | ||
await driver.terminateWorkers(); | ||
}); | ||
|
||
test('single work request', () async { | ||
await _doRequests(driver, count: 1); | ||
}); | ||
|
||
test('lots of requests', () async { | ||
await _doRequests(driver, count: 1000); | ||
}); | ||
}); | ||
} | ||
|
||
/// Runs [count] work requests through [driver], and asserts that they all | ||
/// completed with the correct response. | ||
Future _doRequests(BazelWorkerDriver driver, {int count}) async { | ||
count ??= 100; | ||
var requests = new List.generate(count, (requestNum) { | ||
var request = new WorkRequest(); | ||
request.arguments | ||
.addAll(new List.generate(requestNum, (argNum) => '$argNum')); | ||
return request; | ||
}); | ||
var responses = await Future.wait(requests.map(driver.doWork)); | ||
for (int i = 0; i < responses.length; i++) { | ||
var request = requests[i]; | ||
var response = responses[i]; | ||
expect(response.exitCode, EXIT_CODE_OK); | ||
expect(response.output, request.arguments.join('\n')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters