Skip to content

Commit 075f4d9

Browse files
authored
Correct handling of SystemTimeSource in tests (#195)
- some unit tests did not reset it which lead to errors depending on test order - e.g. ResynchTest and AcceptanceTests were failing constantly on my machine because LogUtilTest did not reset the SystemTimeSource and as a result the Session did not send out any heartbeats
1 parent 5b25019 commit 075f4d9

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

quickfixj-core/src/test/java/quickfix/FileLogTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.io.FileInputStream;
2626
import java.io.IOException;
2727
import java.util.Date;
28+
import org.junit.After;
2829

2930
import org.junit.Before;
3031
import org.junit.Test;
@@ -39,6 +40,11 @@ public void setUp() throws Exception {
3940
SystemTime.setTimeSource(new MockSystemTimeSource(System.currentTimeMillis()));
4041
}
4142

43+
@After
44+
public void tearDown() throws Exception {
45+
SystemTime.setTimeSource(null);
46+
}
47+
4248
@Test
4349
public void testLog() throws Exception {
4450
long systemTime = System.currentTimeMillis();

quickfixj-core/src/test/java/quickfix/LogUtilTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,28 @@
1919

2020
package quickfix;
2121

22-
import junit.framework.TestCase;
23-
2422
import java.io.ByteArrayOutputStream;
2523
import java.io.IOException;
2624
import java.io.PrintStream;
2725
import java.util.Date;
26+
import org.junit.After;
27+
import static org.junit.Assert.assertTrue;
28+
import org.junit.Before;
29+
import org.junit.Test;
2830

29-
public class LogUtilTest extends TestCase {
31+
public class LogUtilTest {
3032

31-
protected void setUp() throws Exception {
32-
super.setUp();
33+
@Before
34+
public void setUp() throws Exception {
3335
SystemTime.setTimeSource(new MockSystemTimeSource(System.currentTimeMillis()));
3436
}
3537

38+
@After
39+
public void tearDown() throws Exception {
40+
SystemTime.setTimeSource(null);
41+
}
42+
43+
@Test
3644
public void testLogThrowable() throws ConfigError, FieldConvertError {
3745
ByteArrayOutputStream data = new ByteArrayOutputStream();
3846
LogFactory mockLogFactory = createLogFactory(data);

quickfixj-core/src/test/java/quickfix/test/acceptance/AcceptanceTestSuite.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Map;
2828
import java.util.concurrent.ExecutorService;
2929
import java.util.concurrent.Executors;
30+
import quickfix.SystemTime;
3031

3132
public class AcceptanceTestSuite extends TestSuite {
3233
private static final String ATEST_TIMEOUT_KEY = "atest.timeout";
@@ -153,6 +154,8 @@ public AcceptanceTestSuite(String testDirectory, boolean multithreaded) {
153154
public AcceptanceTestSuite(String testDirectory, boolean multithreaded, Map<Object, Object> overridenProperties) {
154155
this.multithreaded = multithreaded;
155156
this.overridenProperties = overridenProperties;
157+
SystemTime.setTimeSource(null);
158+
156159
String name = testDirectory.substring(testDirectory.lastIndexOf(File.separatorChar) + 1);
157160
this.setName(name + (multithreaded ? "-threaded" : ""));
158161
Long timeout = Long.getLong(ATEST_TIMEOUT_KEY);

0 commit comments

Comments
 (0)