|
17 | 17 |
|
18 | 18 | import java.sql.SQLException;
|
19 | 19 | import java.util.Map;
|
| 20 | +import java.util.concurrent.TimeUnit; |
20 | 21 |
|
21 | 22 | import static apoc.util.TestUtil.testCall;
|
22 | 23 | import static apoc.util.TestUtil.testResult;
|
23 | 24 | import static org.junit.Assert.assertArrayEquals;
|
24 | 25 | import static org.junit.Assert.assertEquals;
|
25 | 26 | import static org.junit.Assert.assertFalse;
|
26 | 27 | import static org.junit.Assert.assertTrue;
|
| 28 | +import static org.neo4j.test.assertion.Assert.assertEventually; |
27 | 29 |
|
28 | 30 | public class PostgresJdbcTest extends AbstractJdbcTest {
|
29 | 31 |
|
@@ -132,19 +134,22 @@ public void testIssue4141PeriodicIterateWithJdbc() throws Exception {
|
132 | 134 | assertPgStatActivityHasOnlyActiveState();
|
133 | 135 | }
|
134 | 136 |
|
135 |
| - private static void assertPgStatActivityHasOnlyActiveState() throws Exception { |
136 |
| - // connect to postgres and execute the query `select state from pg_stat_activity` |
137 |
| - String psql = postgress.execInContainer( |
138 |
| - "psql", "postgresql://test:test@localhost/test", "-c", "select state from pg_stat_activity;") |
139 |
| - .toString(); |
140 |
| - |
141 |
| - assertTrue("Current pg_stat_activity is: " + psql, psql.contains("active")); |
142 |
| - |
143 |
| - // the result without the https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/4141 change |
144 |
| - // is not deterministic, can be `too many clients already` or (not very often) `idle` |
145 |
| - assertFalse("Current pg_stat_activity is: " + psql, |
146 |
| - psql.contains("too many clients already") || psql.contains("idle")); |
147 |
| - |
| 137 | + private static void assertPgStatActivityHasOnlyActiveState() { |
| 138 | + assertEventually(() -> { |
| 139 | + // connect to postgres and execute the query `select state from pg_stat_activity` |
| 140 | + String psql = postgress.execInContainer( |
| 141 | + "psql", "postgresql://test:test@localhost/test", "-c", "select state from pg_stat_activity;") |
| 142 | + .toString(); |
| 143 | + |
| 144 | + assertTrue("Current pg_stat_activity is: " + psql, psql.contains("active")); |
| 145 | + |
| 146 | + // the result without the https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/4141 change |
| 147 | + // is not deterministic, can be `too many clients already` or (not very often) `idle` |
| 148 | + assertFalse("Current pg_stat_activity is: " + psql, |
| 149 | + psql.contains("too many clients already") || psql.contains("idle")); |
| 150 | + |
| 151 | + return true; |
| 152 | + }, v -> v, 20L, TimeUnit.SECONDS); |
148 | 153 | }
|
149 | 154 |
|
150 | 155 | private void assertPeriodicIterate(Result result) {
|
|
0 commit comments