Skip to content

Commit 543e482

Browse files
authored
graphql: make coverage recording thread safe (#739)
1 parent bb8d01b commit 543e482

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

webtau-graphql/src/main/java/org/testingisdocumenting/webtau/graphql/GraphQLCoveredQueries.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,20 @@
1616

1717
package org.testingisdocumenting.webtau.graphql;
1818

19-
import java.util.LinkedHashMap;
20-
import java.util.LinkedHashSet;
2119
import java.util.Map;
2220
import java.util.Set;
21+
import java.util.concurrent.ConcurrentHashMap;
2322
import java.util.stream.Stream;
2423

2524
public class GraphQLCoveredQueries {
2625
private final Map<GraphQLQuery, Set<Call>> actualCallsIdsByQuery;
2726

2827
GraphQLCoveredQueries() {
29-
actualCallsIdsByQuery = new LinkedHashMap<>();
28+
actualCallsIdsByQuery = new ConcurrentHashMap<>();
3029
}
3130

3231
public void add(GraphQLQuery query, String id, long elapsedTime) {
33-
Set<Call> calls = actualCallsIdsByQuery.computeIfAbsent(query, k -> new LinkedHashSet<>());
32+
Set<Call> calls = actualCallsIdsByQuery.computeIfAbsent(query, k -> ConcurrentHashMap.newKeySet());
3433

3534
calls.add(new Call(id, elapsedTime));
3635
}

webtau-graphql/src/test/groovy/org/testingisdocumenting/webtau/graphql/GraphQLReportDataProviderTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class GraphQLReportDataProviderTest {
4141
void "computes timing per query"() {
4242
def timeStats = reportDataProvider.provide(null)
4343
.find {it.getId() == "graphQLQueryTimeStatistics" }
44-
.getData()
44+
.getData() as Set
4545
def expectedStats = [
4646
[
4747
name: 'allTasks',
@@ -67,7 +67,7 @@ class GraphQLReportDataProviderTest {
6767
p99: 6
6868
]
6969
]
70-
]
70+
] as Set
7171
timeStats.should == expectedStats
7272
}
7373

0 commit comments

Comments
 (0)