Skip to content

Commit 01b0001

Browse files
aamcommit-bot@chromium.org
authored andcommitted
[vm/transferable] Refactor oom transferable test out of other throwing tests.
Issue dartbug.com/37188. Change-Id: Iba8f3bb2f9d8e399f75bd3c63e4542effa6eeb57 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105347 Reviewed-by: Ryan Macnak <[email protected]> Commit-Queue: Alexander Aprelev <[email protected]>
1 parent 19447e1 commit 01b0001

File tree

3 files changed

+46
-26
lines changed

3 files changed

+46
-26
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Test that ensures correct exception when running out of memory for
6+
// really large transferable.
7+
8+
import 'dart:async';
9+
import 'dart:collection';
10+
import 'dart:core';
11+
import 'dart:io';
12+
import 'dart:isolate';
13+
import 'dart:typed_data';
14+
import 'dart:math';
15+
16+
import "package:expect/expect.dart";
17+
18+
main() {
19+
// Attempt to create total 1tb uint8list which should fail on 32 and 64-bit
20+
// platforms.
21+
final bytes100MB = Uint8List(100 * 1024 * 1024);
22+
final total1TB = List<Uint8List>.filled(10000, bytes100MB);
23+
// Try to make a 1 TB transferable.
24+
Expect.throws(() => TransferableTypedData.fromList(total1TB));
25+
}

runtime/tests/vm/dart/transferable_throws_test.dart

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// Test that ensures correct exception is thrown when attempting to use
6-
// transferred transferables.
5+
// Test that ensures correct exceptions are thrown when misusing
6+
// [TransferableTypedData].
77

88
import 'dart:async';
99
import 'dart:collection';
@@ -15,20 +15,30 @@ import 'dart:math';
1515

1616
import "package:expect/expect.dart";
1717

18-
throwsIfMaterializeAfterSend() {
19-
final rp = ReceivePort();
18+
throwsIfMaterializeAfterSend() async {
19+
final completer = Completer<bool>();
20+
final rp = ReceivePort()
21+
..listen((e) {
22+
completer.complete(true);
23+
});
2024
final transferable = TransferableTypedData.fromList([Uint8List(1024)]);
2125
rp.sendPort.send(transferable);
2226
Expect.throwsArgumentError(() => transferable.materialize());
27+
await completer.future;
2328
rp.close();
2429
}
2530

26-
throwsIfSendMoreThanOnce() {
27-
final rp = ReceivePort();
31+
throwsIfSendMoreThanOnce() async {
32+
final completer = Completer<bool>();
33+
final rp = ReceivePort()
34+
..listen((e) {
35+
completer.complete(true);
36+
});
2837
final bytes = Uint8List(1024);
2938
final transferable = TransferableTypedData.fromList([bytes]);
3039
rp.sendPort.send(transferable);
3140
Expect.throwsArgumentError(() => rp.sendPort.send(transferable));
41+
await completer.future;
3242
rp.close();
3343
}
3444

@@ -39,7 +49,6 @@ throwsIfMaterializeMoreThanOnce() {
3949
}
4050

4151
throwsIfReceiverMaterializesMoreThanOnce() async {
42-
final rp = ReceivePort();
4352
final completer = Completer<List>();
4453
final isolateErrors = ReceivePort()..listen((e) => completer.complete(e));
4554
await Isolate.spawn(
@@ -51,7 +60,6 @@ throwsIfReceiverMaterializesMoreThanOnce() async {
5160
"Invalid argument(s): Attempt to materialize object that was"
5261
" transferred already.");
5362
isolateErrors.close();
54-
rp.close();
5563
}
5664

5765
void receiver(final transferable) {
@@ -74,15 +82,6 @@ throwsIfCummulativeListIsTooLargeOn32bitPlatform() {
7482
() => TransferableTypedData.fromList([halfmax, halfmax, Uint8List(2)]));
7583
}
7684

77-
throwsIfCummulativeListCantBeAllocated() {
78-
// Attempt to create total 1tb uint8list which should fail on 32 and 64-bit
79-
// platforms.
80-
final bytes100MB = Uint8List(100 * 1024 * 1024);
81-
final total1TB = List<Uint8List>.filled(10000, bytes100MB);
82-
// Try to make a 1 TB transferable.
83-
Expect.throws(() => TransferableTypedData.fromList(total1TB));
84-
}
85-
8685
class MyList<T> extends ListBase<T> {
8786
@override
8887
int length;
@@ -97,16 +96,12 @@ class MyTypedData implements TypedData {
9796
noSuchMethod(_) {}
9897
}
9998

100-
main() {
101-
throwsIfMaterializeAfterSend();
102-
throwsIfSendMoreThanOnce();
99+
main() async {
100+
await throwsIfMaterializeAfterSend();
101+
await throwsIfSendMoreThanOnce();
103102
throwsIfMaterializeMoreThanOnce();
104-
throwsIfReceiverMaterializesMoreThanOnce();
103+
await throwsIfReceiverMaterializesMoreThanOnce();
105104
throwsIfCummulativeListIsTooLargeOn32bitPlatform();
106-
if (!Platform.isMacOS) {
107-
// this test crashes the process on mac.
108-
throwsIfCummulativeListCantBeAllocated();
109-
}
110105

111106
Expect.throwsArgumentError(() => TransferableTypedData.fromList(null));
112107
Expect.throwsArgumentError(() => TransferableTypedData.fromList([null]));

runtime/tests/vm/vm.status

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ dart/redirection_type_shuffling_test/none: RuntimeError
5656
dart/catch_entry_state: SkipByDesign
5757

5858
[ $builder_tag == asan ]
59-
dart/transferable_throws_test: SkipByDesign # This test tries to allocate too much memory on purpose. Still dartbug.com/37188
59+
dart/transferable_throws_oom_test: SkipByDesign # This test tries to allocate too much memory on purpose. Still dartbug.com/37188
6060

6161
[ $compiler != dartk && $compiler != dartkb ]
6262
cc/IsolateReload_KernelIncrementalCompile: SkipByDesign

0 commit comments

Comments
 (0)