Files
sdk/tests/standalone_2/io/https_nonblocking_trust_evaluation_test.dart
T
Alexander Aprelev 340f78eab3 [vm/io] Add a test for nonblocking ssl certification evaluation.
This is follow-up to a6dafabb88.

Fixes https://github.com/dart-lang/sdk/issues/43674

Change-Id: I4da732ab08235a1f549d45c7fa5fb87db672e2aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166701
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2020-10-12 15:06:52 +00:00

55 lines
1.5 KiB
Dart

// Copyright (c) 2020, 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.
// VMOptions=--long-ssl-cert-evaluation
// This test verifies that dart isolate is not getting blocked during
// certificate evaluation.
import 'dart:async';
import 'dart:io';
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
void log(String s) {
print(s);
}
Timer stallDetector() {
final sw = Stopwatch()..start();
return Timer.periodic(Duration(milliseconds: 5), (_) {
int elapsedMs = sw.elapsedMilliseconds;
// Would the evaluation be synchronous, the dart isolate is going to
// be blocked for over a second.
Expect.isTrue(elapsedMs < 1000);
if (sw.elapsedMilliseconds > 10) {
log('EVENT LOOP WAS STALLED FOR ${sw.elapsedMilliseconds} ms');
}
sw.reset();
});
}
void main() async {
asyncStart();
final url = 'https://google.com';
final timer = stallDetector();
var sw = Stopwatch()..start();
var httpClient = HttpClient();
try {
var request = await httpClient.getUrl(Uri.parse(url));
var response = await request.close();
int elapsedMs = sw.elapsedMilliseconds;
log('REQUEST COMPLETE IN $elapsedMs ms');
// Request have to take at least a second due to
// vm "--long-ssl-cert-evaluation" option.
Expect.isTrue(elapsedMs > 1000);
asyncEnd();
} finally {
httpClient.close(force: true);
timer.cancel();
}
}