Skip to content

Commit 452b051

Browse files
Replace assertCypherResult to fix flakey test
Co-authored-by: Veselin Nikolov <[email protected]>
1 parent 6dfb531 commit 452b051

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

examples/pregel-example/src/test/java/org/neo4j/gds/beta/pregel/pr/PageRankPregelProcTest.java

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
package org.neo4j.gds.beta.pregel.pr;
2121

22+
import org.assertj.core.data.Offset;
2223
import org.junit.jupiter.api.BeforeEach;
2324
import org.junit.jupiter.api.Test;
2425
import org.neo4j.gds.BaseProcTest;
@@ -27,10 +28,10 @@
2728
import org.neo4j.gds.core.utils.mem.MemoryRange;
2829
import org.neo4j.gds.extension.Neo4jGraph;
2930

30-
import java.util.List;
3131
import java.util.Map;
3232

33-
import static org.hamcrest.Matchers.closeTo;
33+
import static org.assertj.core.api.Assertions.assertThat;
34+
import static org.assertj.core.api.InstanceOfAssertFactories.DOUBLE;
3435
import static org.neo4j.gds.TestSupport.assertCypherMemoryEstimation;
3536
import static org.neo4j.gds.beta.pregel.pr.PageRankPregel.PAGE_RANK;
3637

@@ -70,24 +71,24 @@ class PageRankPregelProcTest extends BaseProcTest {
7071

7172
private static final double RESULT_ERROR = 1e-3;
7273

73-
private List<Map<String, Object>> expected;
74+
private Map<Long, Double> expected;
7475

7576
@BeforeEach
7677
void setup() throws Exception {
7778
registerProcedures(GraphProjectProc.class, PageRankPregelStreamProc.class, PageRankPregelMutateProc.class);
7879

79-
expected = List.of(
80-
Map.of("nodeId", idFunction.of("a"), "score", closeTo(0.0276D, RESULT_ERROR)),
81-
Map.of("nodeId", idFunction.of("b"), "score", closeTo(0.3483D, RESULT_ERROR)),
82-
Map.of("nodeId", idFunction.of("c"), "score", closeTo(0.2650D, RESULT_ERROR)),
83-
Map.of("nodeId", idFunction.of("d"), "score", closeTo(0.0330D, RESULT_ERROR)),
84-
Map.of("nodeId", idFunction.of("e"), "score", closeTo(0.0682D, RESULT_ERROR)),
85-
Map.of("nodeId", idFunction.of("f"), "score", closeTo(0.0330D, RESULT_ERROR)),
86-
Map.of("nodeId", idFunction.of("g"), "score", closeTo(0.0136D, RESULT_ERROR)),
87-
Map.of("nodeId", idFunction.of("h"), "score", closeTo(0.0136D, RESULT_ERROR)),
88-
Map.of("nodeId", idFunction.of("i"), "score", closeTo(0.0136D, RESULT_ERROR)),
89-
Map.of("nodeId", idFunction.of("j"), "score", closeTo(0.0136D, RESULT_ERROR)),
90-
Map.of("nodeId", idFunction.of("k"), "score", closeTo(0.0136D, RESULT_ERROR))
80+
expected = Map.ofEntries(
81+
Map.entry(idFunction.of("a"), 0.0276D),
82+
Map.entry(idFunction.of("b"), 0.3483D),
83+
Map.entry(idFunction.of("c"), 0.2650D),
84+
Map.entry(idFunction.of("d"), 0.0330D),
85+
Map.entry(idFunction.of("e"), 0.0682D),
86+
Map.entry(idFunction.of("f"), 0.0330D),
87+
Map.entry(idFunction.of("g"), 0.0136D),
88+
Map.entry(idFunction.of("h"), 0.0136D),
89+
Map.entry(idFunction.of("i"), 0.0136D),
90+
Map.entry(idFunction.of("j"), 0.0136D),
91+
Map.entry(idFunction.of("k"), 0.0136D)
9192
);
9293
}
9394

@@ -100,7 +101,17 @@ void stream() {
100101
.addParameter("maxIterations", 10)
101102
.yields("nodeId", "values");
102103

103-
assertCypherResult(query + " RETURN nodeId, values.pagerank AS score", expected);
104+
var rowCount = runQueryWithRowConsumer(
105+
query + " RETURN nodeId as nodeId, values.pagerank AS score",
106+
resultRow -> {
107+
var nodeId = resultRow.getNumber("nodeId").longValue();
108+
var expectedScore = expected.get(nodeId);
109+
assertThat(resultRow.getNumber("score"))
110+
.asInstanceOf(DOUBLE).isCloseTo(expectedScore, Offset.offset(RESULT_ERROR));
111+
}
112+
);
113+
114+
assertThat(rowCount).isEqualTo(expected.size());
104115
}
105116

106117
@Test
@@ -143,6 +154,16 @@ void streamSeeded() {
143154
.addParameter("seedProperty", "value_" + PAGE_RANK)
144155
.yields("nodeId", "values");
145156

146-
assertCypherResult(query + " RETURN nodeId, values.pagerank AS score", expected);
157+
var rowCount = runQueryWithRowConsumer(
158+
query + " RETURN nodeId, values.pagerank AS score",
159+
resultRow -> {
160+
var nodeId = resultRow.getNumber("nodeId").longValue();
161+
var expectedScore = expected.get(nodeId);
162+
assertThat(resultRow.getNumber("score"))
163+
.asInstanceOf(DOUBLE).isCloseTo(expectedScore, Offset.offset(RESULT_ERROR));
164+
}
165+
);
166+
167+
assertThat(rowCount).isEqualTo(expected.size());
147168
}
148169
}

0 commit comments

Comments
 (0)