Skip to content

Commit a8eea36

Browse files
authored
test: Simple ChartData tests for JS API (#6549)
Also fixed a testing issue discovered where custom transport tests can cause other tests to accidentally reuse that transport, receive bad data from the "server". Follow-up #6546
1 parent 94de73a commit a8eea36

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

web/client-api/src/test/java/io/deephaven/web/ClientIntegrationTestSuite.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io.deephaven.web.client.api.storage.JsStorageServiceTestGwt;
1010
import io.deephaven.web.client.api.subscription.ConcurrentTableTestGwt;
1111
import io.deephaven.web.client.api.subscription.ViewportTestGwt;
12+
import io.deephaven.web.client.api.widget.plot.ChartDataTestGwt;
1213
import io.deephaven.web.client.fu.LazyPromiseTestGwt;
1314
import junit.framework.Test;
1415
import junit.framework.TestSuite;
@@ -32,6 +33,7 @@ public static Test suite() {
3233
suite.addTestSuite(InputTableTestGwt.class);
3334
suite.addTestSuite(ColumnStatisticsTestGwt.class);
3435
suite.addTestSuite(GrpcTransportTestGwt.class);
36+
suite.addTestSuite(ChartDataTestGwt.class);
3537

3638
// This should be a unit test, but it requires a browser environment to run on GWT 2.9
3739
// GWT 2.9 doesn't have proper bindings for Promises in HtmlUnit, so we need to use the IntegrationTest suite
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<module>
2+
<!-- This test runs in its own module to avoid risking poisoning other tests with its broken custom transports -->
3+
<inherits name="io.deephaven.web.DeephavenIntegrationTest" />
4+
</module>

web/client-api/src/test/java/io/deephaven/web/client/api/grpc/GrpcTransportTestGwt.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
public class GrpcTransportTestGwt extends AbstractAsyncGwtTestCase {
1717
@Override
1818
public String getModuleName() {
19-
return "io.deephaven.web.DeephavenIntegrationTest";
19+
// This test runs in its own module to avoid risking poisoning other tests with its broken custom transports
20+
return "io.deephaven.web.CustomTransportTest";
2021
}
2122

2223
/**
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//
2+
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
3+
//
4+
package io.deephaven.web.client.api.widget.plot;
5+
6+
import elemental2.promise.Promise;
7+
import io.deephaven.web.client.api.AbstractAsyncGwtTestCase;
8+
import io.deephaven.web.client.api.subscription.AbstractTableSubscription;
9+
import io.deephaven.web.client.api.subscription.TableSubscription;
10+
11+
public class ChartDataTestGwt extends AbstractAsyncGwtTestCase {
12+
private final AbstractAsyncGwtTestCase.TableSourceBuilder tables = new AbstractAsyncGwtTestCase.TableSourceBuilder()
13+
.script("from deephaven import time_table")
14+
.script("appending_table", "time_table('PT0.1s').update([\"A = i % 2\", \"B = `` + A\"])")
15+
.script("updating_table", "appending_table.last_by('A')");
16+
17+
@Override
18+
public String getModuleName() {
19+
return "io.deephaven.web.DeephavenIntegrationTest";
20+
}
21+
22+
public void testAppendingChartData() {
23+
connect(tables)
24+
.then(table("appending_table"))
25+
.then(table -> {
26+
ChartData chartData = new ChartData(table);
27+
TableSubscription sub = table.subscribe(table.getColumns());
28+
29+
// Handle at least one event with data
30+
int[] count = {0};
31+
32+
return new Promise<AbstractTableSubscription.SubscriptionEventData>((resolve, reject) -> {
33+
delayTestFinish(12301);
34+
sub.addEventListener(TableSubscription.EVENT_UPDATED, event -> {
35+
AbstractTableSubscription.SubscriptionEventData data =
36+
(AbstractTableSubscription.SubscriptionEventData) event.getDetail();
37+
chartData.update(data);
38+
39+
if (count[0] > 0) {
40+
// Don't test on the first update, could still be empty
41+
assertTrue(chartData.getColumn("A", arr -> arr, data).length > 0);
42+
43+
resolve.onInvoke(data);
44+
}
45+
count[0]++;
46+
});
47+
}).then(data -> {
48+
sub.close();
49+
table.close();
50+
return Promise.resolve(data);
51+
});
52+
})
53+
.then(this::finish).catch_(this::report);
54+
}
55+
56+
public void testModifiedChartData() {
57+
connect(tables)
58+
.then(table("updating_table"))
59+
.then(table -> {
60+
ChartData chartData = new ChartData(table);
61+
TableSubscription sub = table.subscribe(table.getColumns());
62+
63+
int[] count = {0};
64+
return new Promise<AbstractTableSubscription.SubscriptionEventData>((resolve, reject) -> {
65+
delayTestFinish(12302);
66+
sub.addEventListener(TableSubscription.EVENT_UPDATED, event -> {
67+
68+
AbstractTableSubscription.SubscriptionEventData data =
69+
(AbstractTableSubscription.SubscriptionEventData) event.getDetail();
70+
71+
chartData.update(data);
72+
if (count[0] > 0) {
73+
// Don't test on the first update, could still be empty
74+
assertTrue(chartData.getColumn("A", arr -> arr, data).length > 0);
75+
}
76+
77+
if (count[0] > 2) {
78+
// We've seen at least three updates, and must have modified rows at least once
79+
resolve.onInvoke((AbstractTableSubscription.SubscriptionEventData) event.getDetail());
80+
}
81+
count[0]++;
82+
});
83+
})
84+
.then(data -> {
85+
sub.close();
86+
table.close();
87+
return Promise.resolve(data);
88+
});
89+
})
90+
.then(this::finish).catch_(this::report);
91+
}
92+
}

0 commit comments

Comments
 (0)