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

Unified Diff: pkg/analysis_server/test/timing/completion/completion_simple.dart

Issue 625973002: Initial timing framework and test for server (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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
Index: pkg/analysis_server/test/timing/completion/completion_simple.dart
diff --git a/pkg/analysis_server/test/timing/completion/completion_simple.dart b/pkg/analysis_server/test/timing/completion/completion_simple.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d971d9afaa9a481c4f64233423be9104e4e34918
--- /dev/null
+++ b/pkg/analysis_server/test/timing/completion/completion_simple.dart
@@ -0,0 +1,117 @@
+// Copyright (c) 2014, 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.
+
+library test.timing.simple;
+
+import 'dart:async';
+
+import '../timing_framework.dart';
+
+/**
+ * Perform the timing test, printing the minimum time to the output.
scheglov 2014/10/03 16:46:14 Not only the minimum time.
Brian Wilkerson 2014/10/03 17:17:37 Done
+ */
+void main(List<String> args) {
+ SimpleTest test = new SimpleTest();
+ test.run().then((TimingResult result) {
+ print('minTime = ${result.minTime}');
+ print('averageTime = ${result.averageTime}');
+ print('maxTime = ${result.maxTime}');
+ print('standardDeviation = ${result.standardDeviation}');
+ });
+}
+
+/**
+ * A test of how long it takes to get code completion results after making a
+ * minor change inside a method body.
+ */
+class SimpleTest extends TimingTest {
+ /**
+ * The path to the file in which code completion is to be performed.
+ */
+ String mainFilePath;
+
+ /**
+ * The original content of the file.
+ */
+ String originalContent;
+
+ /**
+ * The offset of the cursor when requesting code completion.
+ */
+ int cursorOffset;
+
+ /**
+ * A completer that will be completed when code completion results have been
+ * received from the server.
+ */
+ Completer completionReceived;
+
+ /**
+ * Initialize a newly created test.
+ */
+ SimpleTest();
+
+ @override
+ Future oneTimeSetUp() {
+ return super.oneTimeSetUp().then((_) {
+ mainFilePath = sourcePath('test.dart');
+ originalContent = r'''
+class C {
+ m() {
+ return 0;
+ }
+}
+
+f(C c) {
+ return c;
+}
+''';
+ cursorOffset = originalContent.indexOf('c;') + 1;
+ writeFile(mainFilePath, originalContent);
+ });
+ }
+
+ @override
+ Future setUp() {
+ completionReceived = new Completer();
+ onCompletionResults.listen((_) {
+ // We only care about the time to the first response.
+ if (!completionReceived.isCompleted) {
+ completionReceived.complete();
+ }
+ });
+ int separatorIndex = mainFilePath.lastIndexOf('/');
Paul Berry 2014/10/03 16:58:35 I think this will be wrong on Windows. Instead us
Brian Wilkerson 2014/10/03 17:17:37 Done
+ String mainDirectory = mainFilePath.substring(0, separatorIndex);
scheglov 2014/10/03 16:46:14 We could use package:path for this.
Brian Wilkerson 2014/10/03 17:17:37 Done
+ sendAnalysisSetAnalysisRoots([mainDirectory], []);
+ sendAnalysisUpdateContent({
+ mainFilePath: {
+ 'type': 'add',
+ 'content': originalContent
+ }
+ });
+ return new Future.value();
+ }
+
+ @override
+ Future perform() {
+ sendAnalysisUpdateContent({
+ mainFilePath: {
+ 'type': 'change',
+ 'edits': [{
+ 'offset': cursorOffset,
+ 'length': 0,
+ 'replacement': '.'
+ }]
+ }
+ });
+ sendCompletionGetSuggestions(mainFilePath, cursorOffset + 1);
+ return completionReceived.future;
+ }
+
+ @override
+ Future tearDown() {
+ sendAnalysisSetAnalysisRoots([], []);
+ return new Future.value();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698