Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Unified Diff: pkg/barback/test/asset_test.dart

Issue 55983005: Serialize barback assets more efficiently. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/barback/lib/src/utils.dart ('k') | sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/test/asset_test.dart
diff --git a/pkg/barback/test/asset_test.dart b/pkg/barback/test/asset_test.dart
index 74f459ed5c3a99deb8e062bf7f4c31ce19ff0b5b..9312fb0452c2d1ea5a940250f5394d71b7cc350f 100644
--- a/pkg/barback/test/asset_test.dart
+++ b/pkg/barback/test/asset_test.dart
@@ -7,8 +7,10 @@ library barback.test.asset_test;
import 'dart:async';
import 'dart:convert';
import 'dart:io';
+import 'dart:isolate';
import 'package:barback/barback.dart';
+import 'package:barback/src/internal_asset.dart';
import 'package:path/path.dart' as pathos;
import 'package:unittest/unittest.dart';
@@ -215,4 +217,52 @@ main() {
});
});
});
+
+ group("across isolates", () {
+ getBytesFromIsolate(Asset asset) {
+ var port = new ReceivePort();
+ return Isolate.spawn(_getAssetBytes, {
+ 'asset': serializeAsset(asset),
+ 'replyTo': port.sendPort
+ }).then((_) => port.first);
+ }
+
+ test("gets the UTF-8-encoded string for a string asset", () {
+ var asset = new Asset.fromString(id, "çøñ†éℵ™");
+ expect(getBytesFromIsolate(asset),
+ completion(equals(UTF8.encode("çøñ†éℵ™"))));
+ });
+
+ test("gets the raw bytes for a byte asset", () {
+ var asset = new Asset.fromBytes(id, binaryContents);
+ expect(getBytesFromIsolate(asset),
+ completion(equals(binaryContents)));
+ });
+
+ test("gets the raw bytes for a binary file", () {
+ var asset = new Asset.fromPath(id, binaryFilePath);
+ expect(getBytesFromIsolate(asset),
+ completion(equals(binaryContents)));
+ });
+
+ test("gets the raw bytes for a text file", () {
+ var asset = new Asset.fromPath(id, textFilePath);
+ expect(getBytesFromIsolate(asset),
+ completion(equals(UTF8.encode("çøñ†éℵ™"))));
+ });
+
+ test("gets the raw bytes for a stream", () {
+ var asset = new Asset.fromStream(id,
+ new Stream.fromFuture(new Future.value(UTF8.encode("çøñ†éℵ™"))));
+ expect(getBytesFromIsolate(asset),
+ completion(equals(UTF8.encode("çøñ†éℵ™"))));
+ });
+ });
+}
+
+void _getAssetBytes(message) {
+ var asset = deserializeAsset(message['asset']);
+ var builder = asset.read().fold(new BytesBuilder(),
+ (builder, chunk) => builder..add(chunk));
+ builder.then((builder) => message['replyTo'].send(builder.takeBytes()));
}
« no previous file with comments | « pkg/barback/lib/src/utils.dart ('k') | sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698