Skip to content

Commit 29e5c3a

Browse files
committed
Make test fail after timeout, if it does fail then the user has mixed locale and no obvious workaround ATM. Fail is better then hanging.
1 parent 7a18f1a commit 29e5c3a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

storage/inchi/src/main/java/org/openscience/cdk/inchi/JniInChIInputAdapter.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,17 @@ private static boolean isTimeoutOptions(String op) {
6161
pos++;
6262
while (pos < len && Character.isDigit(op.charAt(pos)))
6363
pos++;
64-
if (pos < len && op.charAt(pos) == '.')
64+
if (pos < len && (op.charAt(pos) == '.' || op.charAt(pos) == ','))
6565
pos++;
6666
while (pos < len && Character.isDigit(op.charAt(pos)))
6767
pos++;
6868
return pos == len;
6969
}
7070

71+
private static boolean isSubSecondTimeout(String op) {
72+
return op.indexOf('.') >= 0 || op.indexOf(',') >= 0;
73+
}
74+
7175
private static String checkOptions(final String ops) throws JniInchiException {
7276
if (ops == null) {
7377
throw new IllegalArgumentException("Null options");
@@ -92,7 +96,8 @@ private static String checkOptions(final String ops) throws JniInchiException {
9296
sbOptions.append(" ");
9397
}
9498
} else if (isTimeoutOptions(op)) {
95-
if (op.contains(".") || op.contains(",")) { // only reformat if we actually have a decimal
99+
// only reformat if we actually have a decimal
100+
if (isSubSecondTimeout(op)) {
96101
// because the JNI-InChI library is expecting an platform number, format it as such
97102
Double time = Double.parseDouble(op.substring(1));
98103
DecimalFormat format = new DecimalFormat("#.##");
@@ -132,7 +137,6 @@ else if ("KET".equals(op)) {
132137
return sbOptions.toString();
133138
}
134139

135-
136140
private static String checkOptions(List<INCHI_OPTION> ops) throws JniInchiException {
137141
if (ops == null) {
138142
throw new IllegalArgumentException("Null options");

storage/inchi/src/test/java/org/openscience/cdk/inchi/InChIGeneratorTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,11 @@ public void s_penta_2_3_diene_expl_h() throws Exception {
896896
}
897897
}
898898

899-
@Test
899+
// if this test hits the timeout it's likely the users Locale is mixed, the
900+
// InChI library was loaded in one mode and java is in another, the issue
901+
// is InChI takes timeout in seconds and fractional seconds will be either
902+
// 0.1 or 0,1 depending on locale.
903+
@Test(timeout = 500)
900904
public void timeout() throws Exception {
901905
IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
902906
SmilesParser smipar = new SmilesParser(bldr);

0 commit comments

Comments
 (0)