From 937a27ae27f1ae66c528d3e2aeeef236eb656bac Mon Sep 17 00:00:00 2001 From: Alex Black Date: Fri, 7 Feb 2020 18:38:50 +1100 Subject: [PATCH] Small number of test fixes (#220) * Workaround for apache solr RNG algorithm enforcement in tests Signed-off-by: AlexDBlack * DeepWalk gradient check spam reduction Signed-off-by: AlexDBlack * Timeout increase Signed-off-by: AlexDBlack --- .../io/stream/TupleStreamDataSetIteratorTest.java | 14 ++++++++++++++ .../models/deepwalk/DeepWalkGradientCheck.java | 14 +++++++------- .../handler/ModelTupleStreamIntegrationTest.java | 14 ++++++++++++++ .../solr/handler/ModelTupleStreamTest.java | 13 +++++++++++++ .../java/org/deeplearning4j/zoo/MiscTests.java | 2 +- 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/deeplearning4j/deeplearning4j-dataimport-solrj/src/test/java/org/deeplearning4j/nn/dataimport/solr/client/solrj/io/stream/TupleStreamDataSetIteratorTest.java b/deeplearning4j/deeplearning4j-dataimport-solrj/src/test/java/org/deeplearning4j/nn/dataimport/solr/client/solrj/io/stream/TupleStreamDataSetIteratorTest.java index a35c612b1..b0757e67f 100644 --- a/deeplearning4j/deeplearning4j-dataimport-solrj/src/test/java/org/deeplearning4j/nn/dataimport/solr/client/solrj/io/stream/TupleStreamDataSetIteratorTest.java +++ b/deeplearning4j/deeplearning4j-dataimport-solrj/src/test/java/org/deeplearning4j/nn/dataimport/solr/client/solrj/io/stream/TupleStreamDataSetIteratorTest.java @@ -18,6 +18,8 @@ package org.deeplearning4j.nn.dataimport.solr.client.solrj.io.stream; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; import com.carrotsearch.randomizedtesting.ThreadFilter; + +import java.security.SecureRandom; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -44,6 +46,18 @@ import org.nd4j.rng.deallocator.NativeRandomDeallocator; }) public class TupleStreamDataSetIteratorTest extends SolrCloudTestCase { + static { + /* + This is a hack around the backend-dependent nature of secure random implementations + though we can set the secure random algorithm in our pom.xml files (via maven surefire and test.solr.allowed.securerandom) + there isn't a mechanism that is completely platform independent. + By setting it there (for example, to NativePRNG) that makes it pass on some platforms like Linux but fails on some JVMs on Windows + For testing purposes, we don't need strict guarantees around RNG, hence we don't want to enforce the RNG algorithm + */ + String algorithm = new SecureRandom().getAlgorithm(); + System.setProperty("test.solr.allowed.securerandom", algorithm); + } + public static class PrivateDeallocatorThreadsFilter implements ThreadFilter { /** * Reject deallocator threads over whose cleanup this test has no control. diff --git a/deeplearning4j/deeplearning4j-graph/src/test/java/org/deeplearning4j/graph/models/deepwalk/DeepWalkGradientCheck.java b/deeplearning4j/deeplearning4j-graph/src/test/java/org/deeplearning4j/graph/models/deepwalk/DeepWalkGradientCheck.java index 39e91921a..c1aedd47a 100644 --- a/deeplearning4j/deeplearning4j-graph/src/test/java/org/deeplearning4j/graph/models/deepwalk/DeepWalkGradientCheck.java +++ b/deeplearning4j/deeplearning4j-graph/src/test/java/org/deeplearning4j/graph/models/deepwalk/DeepWalkGradientCheck.java @@ -66,7 +66,7 @@ public class DeepWalkGradientCheck extends BaseDL4JTest { for (int i = 0; i < 7; i++) { INDArray vector = deepWalk.getVertexVector(i); assertArrayEquals(new long[] {vectorSize}, vector.shape()); - System.out.println(Arrays.toString(vector.dup().data().asFloat())); +// System.out.println(Arrays.toString(vector.dup().data().asFloat())); } GraphWalkIterator iter = new RandomWalkIterator<>(graph, 8); @@ -182,10 +182,10 @@ public class DeepWalkGradientCheck extends BaseDL4JTest { if (relError > MAX_REL_ERROR && absErr > MIN_ABS_ERROR) fail(msg); - else - System.out.println(msg); +// else +// System.out.println(msg); } - System.out.println(); +// System.out.println(); } } @@ -216,7 +216,7 @@ public class DeepWalkGradientCheck extends BaseDL4JTest { for (int i = 0; i < nVertices; i++) { INDArray vector = deepWalk.getVertexVector(i); assertArrayEquals(new long[] {vectorSize}, vector.shape()); - System.out.println(Arrays.toString(vector.dup().data().asFloat())); +// System.out.println(Arrays.toString(vector.dup().data().asFloat())); } GraphWalkIterator iter = new RandomWalkIterator<>(graph, 10); @@ -295,8 +295,8 @@ public class DeepWalkGradientCheck extends BaseDL4JTest { if (relError > MAX_REL_ERROR && absErr > minAbsError) fail(msg); - else - System.out.println(msg); +// else +// System.out.println(msg); } } diff --git a/deeplearning4j/deeplearning4j-modelexport-solr/src/test/java/org/deeplearning4j/nn/modelexport/solr/handler/ModelTupleStreamIntegrationTest.java b/deeplearning4j/deeplearning4j-modelexport-solr/src/test/java/org/deeplearning4j/nn/modelexport/solr/handler/ModelTupleStreamIntegrationTest.java index 899e3f8fd..31633889a 100644 --- a/deeplearning4j/deeplearning4j-modelexport-solr/src/test/java/org/deeplearning4j/nn/modelexport/solr/handler/ModelTupleStreamIntegrationTest.java +++ b/deeplearning4j/deeplearning4j-modelexport-solr/src/test/java/org/deeplearning4j/nn/modelexport/solr/handler/ModelTupleStreamIntegrationTest.java @@ -18,6 +18,7 @@ package org.deeplearning4j.nn.modelexport.solr.handler; import java.io.File; import java.nio.file.Path; +import java.security.SecureRandom; import com.carrotsearch.randomizedtesting.ThreadFilter; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; @@ -49,6 +50,19 @@ import org.nd4j.rng.deallocator.NativeRandomDeallocator; }) public class ModelTupleStreamIntegrationTest extends SolrCloudTestCase { + static { + /* + This is a hack around the backend-dependent nature of secure random implementations + though we can set the secure random algorithm in our pom.xml files (via maven surefire and test.solr.allowed.securerandom) + there isn't a mechanism that is completely platform independent. + By setting it there (for example, to NativePRNG) that makes it pass on some platforms like Linux but fails on some JVMs on Windows + For testing purposes, we don't need strict guarantees around RNG, hence we don't want to enforce the RNG algorithm + */ + String algorithm = new SecureRandom().getAlgorithm(); + System.setProperty("test.solr.allowed.securerandom", algorithm); + } + + public static class PrivateDeallocatorThreadsFilter implements ThreadFilter { /** * Reject deallocator threads over whose cleanup this test has no control. diff --git a/deeplearning4j/deeplearning4j-modelexport-solr/src/test/java/org/deeplearning4j/nn/modelexport/solr/handler/ModelTupleStreamTest.java b/deeplearning4j/deeplearning4j-modelexport-solr/src/test/java/org/deeplearning4j/nn/modelexport/solr/handler/ModelTupleStreamTest.java index 1cafc143d..80073677f 100644 --- a/deeplearning4j/deeplearning4j-modelexport-solr/src/test/java/org/deeplearning4j/nn/modelexport/solr/handler/ModelTupleStreamTest.java +++ b/deeplearning4j/deeplearning4j-modelexport-solr/src/test/java/org/deeplearning4j/nn/modelexport/solr/handler/ModelTupleStreamTest.java @@ -19,6 +19,7 @@ package org.deeplearning4j.nn.modelexport.solr.handler; import java.io.File; import java.nio.file.Files; import java.nio.file.Path; +import java.security.SecureRandom; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -58,6 +59,18 @@ import org.nd4j.linalg.lossfunctions.LossFunctions; public class ModelTupleStreamTest { + static { + /* + This is a hack around the backend-dependent nature of secure random implementations + though we can set the secure random algorithm in our pom.xml files (via maven surefire and test.solr.allowed.securerandom) + there isn't a mechanism that is completely platform independent. + By setting it there (for example, to NativePRNG) that makes it pass on some platforms like Linux but fails on some JVMs on Windows + For testing purposes, we don't need strict guarantees around RNG, hence we don't want to enforce the RNG algorithm + */ + String algorithm = new SecureRandom().getAlgorithm(); + System.setProperty("test.solr.allowed.securerandom", algorithm); + } + protected List floatsList(int numFloats) { final List floatsList = new ArrayList(); final float[] floats0 = new float[numFloats]; diff --git a/deeplearning4j/deeplearning4j-zoo/src/test/java/org/deeplearning4j/zoo/MiscTests.java b/deeplearning4j/deeplearning4j-zoo/src/test/java/org/deeplearning4j/zoo/MiscTests.java index c92f5acdc..9dea6629a 100644 --- a/deeplearning4j/deeplearning4j-zoo/src/test/java/org/deeplearning4j/zoo/MiscTests.java +++ b/deeplearning4j/deeplearning4j-zoo/src/test/java/org/deeplearning4j/zoo/MiscTests.java @@ -34,7 +34,7 @@ public class MiscTests extends BaseDL4JTest { @Override public long getTimeoutMilliseconds() { - return 120000L; + return 240000L; } @Test