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

Unified Diff: runtime/vm/service_test.cc

Issue 409213004: Initial backend for metrics in Observatory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 | « runtime/vm/service.cc ('k') | sdk/lib/profiler/profiler.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/service_test.cc
diff --git a/runtime/vm/service_test.cc b/runtime/vm/service_test.cc
index 4e695632cb465bc1bcc44726046260502a3a0fb4..23427e846f72e7ec259b29b7f9d1e22396699160 100644
--- a/runtime/vm/service_test.cc
+++ b/runtime/vm/service_test.cc
@@ -1984,6 +1984,91 @@ TEST_CASE(Service_EmbedderIsolateHandler) {
}
+TEST_CASE(Service_MetricsList) {
+ const char* kScript =
+ "import 'dart:profiler';\n"
+ "var port;\n" // Set to our mock port by C++.
+ "\n"
+ "main() {\n"
+ " var counter = new Counter('a.b.c', 'description');\n"
+ " Metrics.register(counter);\n"
+ " return counter;\n"
+ "}\n"
+ "";
+
+ Isolate* isolate = Isolate::Current();
+ Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL);
+ EXPECT_VALID(h_lib);
+ Library& lib = Library::Handle();
+ lib ^= Api::UnwrapHandle(h_lib);
+ EXPECT(!lib.IsNull());
+ Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
+ EXPECT_VALID(result);
+
+ // Build a mock message handler and wrap it in a dart port.
+ ServiceTestMessageHandler handler;
+ Dart_Port port_id = PortMap::CreatePort(&handler);
+ Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
+ EXPECT_VALID(port);
+ EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port));
+
+ Array& service_msg = Array::Handle();
+ service_msg = Eval(h_lib, "[0, port, ['metrics'], [], []]");
+ Service::HandleIsolateMessage(isolate, service_msg);
+ handler.HandleNextMessage();
+ // Expect MetricList.
+ // TODO(johnmccutchan): Test that list length is 1.
+ EXPECT_SUBSTRING("\"type\":\"MetricList\"", handler.msg());
+}
+
+
+TEST_CASE(Service_Metric) {
+ const char* kScript =
+ "import 'dart:profiler';\n"
+ "var port;\n" // Set to our mock port by C++.
+ "\n"
+ "main() {\n"
+ " var counter = new Counter('a.b.c', 'description');\n"
+ " Metrics.register(counter);\n"
+ " return counter;\n"
+ "}\n"
+ "";
+
+ Isolate* isolate = Isolate::Current();
+ Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL);
+ EXPECT_VALID(h_lib);
+ Library& lib = Library::Handle();
+ lib ^= Api::UnwrapHandle(h_lib);
+ EXPECT(!lib.IsNull());
+ Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
+ EXPECT_VALID(result);
+
+ // Build a mock message handler and wrap it in a dart port.
+ ServiceTestMessageHandler handler;
+ Dart_Port port_id = PortMap::CreatePort(&handler);
+ Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
+ EXPECT_VALID(port);
+ EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port));
+
+ // Request existing metric.
+ Array& service_msg = Array::Handle();
+ service_msg = Eval(h_lib, "[0, port, ['metrics', 'a.b.c'], [], []]");
+ Service::HandleIsolateMessage(isolate, service_msg);
+ handler.HandleNextMessage();
+
+ // Expect Counter.
+ EXPECT_SUBSTRING("\"type\":\"Counter\"", handler.msg());
+
+ // Request invalid metric.
+ service_msg = Eval(h_lib, "[0, port, ['metrics', 'a.b.c.d'], [], []]");
+ Service::HandleIsolateMessage(isolate, service_msg);
+ handler.HandleNextMessage();
+
+ // Expect error.
+ EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg());
+}
+
+
// TODO(zra): Remove when tests are ready to enable.
#if !defined(TARGET_ARCH_ARM64)
« no previous file with comments | « runtime/vm/service.cc ('k') | sdk/lib/profiler/profiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698