Fix race in Process Manager (#2748)

* Remove redundant JSON diff logging

* Fix race in process manager test causing intermittent failure
This commit is contained in:
Tom Morris 2020-06-17 15:24:25 -04:00 committed by GitHub
parent 38d14e0abd
commit 77b858db18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 11 deletions

View File

@ -51,6 +51,13 @@ public class ProcessManagerTests {
processManager.queueProcess(process1); processManager.queueProcess(process1);
processManager.queueProcess(process2); processManager.queueProcess(process2);
processManager.onFailedProcess(process1, new IllegalArgumentException("unexpected error")); processManager.onFailedProcess(process1, new IllegalArgumentException("unexpected error"));
// Wait for process to complete to avoid race where they serialize with
// different values for status: running vs done
int total = 0;
while (processManager.hasPending() && total < 1000) {
Thread.sleep(100);
total += 100;
}
String processJson = ParsingUtilities.defaultWriter.writeValueAsString(process2); String processJson = ParsingUtilities.defaultWriter.writeValueAsString(process2);
TestUtils.isSerializedTo(processManager, "{" TestUtils.isSerializedTo(processManager, "{"
+ "\"processes\":["+processJson+"],\n" + "\"processes\":["+processJson+"],\n"

View File

@ -26,7 +26,6 @@
******************************************************************************/ ******************************************************************************/
package com.google.refine.util; package com.google.refine.util;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
import java.io.File; import java.io.File;
@ -83,8 +82,8 @@ public class TestUtils {
JsonNode jsonB = mapper.readValue(actual, JsonNode.class); JsonNode jsonB = mapper.readValue(actual, JsonNode.class);
if (!jsonA.equals(jsonB)) { if (!jsonA.equals(jsonB)) {
jsonDiff(expected, actual); jsonDiff(expected, actual);
fail("Objects above are not equal as JSON strings.");
} }
assertTrue(jsonA.equals(jsonB));
} catch(Exception e) { } catch(Exception e) {
fail("\""+expected+"\" and \""+actual+"\" are not equal as JSON strings."); fail("\""+expected+"\" and \""+actual+"\" are not equal as JSON strings.");
} }
@ -115,15 +114,11 @@ public class TestUtils {
writer = ParsingUtilities.defaultWriter; writer = ParsingUtilities.defaultWriter;
} }
String jacksonJson = writer.writeValueAsString(o); String jacksonJson = writer.writeValueAsString(o);
if(!equalAsJson(targetJson, jacksonJson)) { assertEqualAsJson(targetJson, jacksonJson);
System.out.println("jackson, "+o.getClass().getName()); } catch (JsonProcessingException e) {
jsonDiff(targetJson, jacksonJson); e.printStackTrace();
} fail("jackson serialization failed");
assertEqualAsJson(targetJson, jacksonJson); }
} catch (JsonProcessingException e) {
e.printStackTrace();
fail("jackson serialization failed");
}
} }
/** /**