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

Unified Diff: test/server_handler_test.dart

Issue 1411553006: Add a Server interface. (Closed) Base URL: git@github.com:dart-lang/shelf@master
Patch Set: Code review changes Created 5 years, 2 months 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 | « test/io_server_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/server_handler_test.dart
diff --git a/test/server_handler_test.dart b/test/server_handler_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9cf9063fc334f516d10ea6af03f8f587ffba6316
--- /dev/null
+++ b/test/server_handler_test.dart
@@ -0,0 +1,76 @@
+// Copyright (c) 2015, 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:shelf/shelf.dart';
+import 'package:test/test.dart';
+
+import 'test_util.dart';
+
+void main() {
+ test("passes the URL to the server", () {
+ var serverHandler = new ServerHandler(LOCALHOST_URI);
+ expect(serverHandler.server.url, equals(LOCALHOST_URI));
+ });
+
+ test("pipes a request from ServerHandler.handler to a mounted handler",
+ () async {
+ var serverHandler = new ServerHandler(LOCALHOST_URI);
+ serverHandler.server.mount(asyncHandler);
+
+ var response = await makeSimpleRequest(serverHandler.handler);
+ expect(response.statusCode, equals(200));
+ expect(response.readAsString(), completion(equals('Hello from /')));
+ });
+
+ test("waits until the server's handler is mounted to service a request",
+ () async {
+ var serverHandler = new ServerHandler(LOCALHOST_URI);
+ var future = makeSimpleRequest(serverHandler.handler);
+ await new Future.delayed(Duration.ZERO);
+
+ serverHandler.server.mount(syncHandler);
+ var response = await future;
+ expect(response.statusCode, equals(200));
+ expect(response.readAsString(), completion(equals('Hello from /')));
+ });
+
+ test("stops servicing requests after Server.close is called", () {
+ var serverHandler = new ServerHandler(LOCALHOST_URI);
+ serverHandler.server.mount(expectAsync((_) {}, count: 0));
+ serverHandler.server.close();
+
+ expect(makeSimpleRequest(serverHandler.handler), throwsStateError);
+ });
+
+ test("calls onClose when Server.close is called", () async {
+ var onCloseCalled = false;
+ var completer = new Completer();
+ var serverHandler = new ServerHandler(LOCALHOST_URI, onClose: () {
+ onCloseCalled = true;
+ return completer.future;
+ });
+
+ var closeDone = false;
+ serverHandler.server.close().then((_) {
+ closeDone = true;
+ });
+ expect(onCloseCalled, isTrue);
+ await new Future.delayed(Duration.ZERO);
+
+ expect(closeDone, isFalse);
+ completer.complete();
+ await new Future.delayed(Duration.ZERO);
+
+ expect(closeDone, isTrue);
+ });
+
+ test("doesn't allow Server.mount to be called multiple times", () {
+ var serverHandler = new ServerHandler(LOCALHOST_URI);
+ serverHandler.server.mount((_) {});
+ expect(() => serverHandler.server.mount((_) {}), throwsStateError);
+ expect(() => serverHandler.server.mount((_) {}), throwsStateError);
+ });
+}
« no previous file with comments | « test/io_server_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698