From 9481f317e17c9d7a16ec6e94ed86ed401f084c35 Mon Sep 17 00:00:00 2001 From: Les Hazlewood <121180+lhazlewood@users.noreply.github.com> Date: Mon, 3 Feb 2020 13:41:30 -0800 Subject: [PATCH] Resolves #552 : changed mock implementation to speed up a very slow test (#553) --- .../jsonwebtoken/SignatureAlgorithmTest.groovy | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/api/src/test/groovy/io/jsonwebtoken/SignatureAlgorithmTest.groovy b/api/src/test/groovy/io/jsonwebtoken/SignatureAlgorithmTest.groovy index 3203095f..ec765cfa 100644 --- a/api/src/test/groovy/io/jsonwebtoken/SignatureAlgorithmTest.groovy +++ b/api/src/test/groovy/io/jsonwebtoken/SignatureAlgorithmTest.groovy @@ -881,6 +881,20 @@ class SignatureAlgorithmTest { } private static BigInteger bigInteger(int bitLength) { - return new BigInteger(bitLength, 0, Random.newInstance()) + BigInteger result = null + // https://github.com/jwtk/jjwt/issues/552: + // + // This method just used to be simply: + // + // return new BigInteger(bitLength, 0, Random.newInstance()) + // + // However, this was unbearably slow due to the 2nd certainty argument of the BigInteger constructor. Since + // we don't need ideal randomness for this method (we're just using it as a mock value), + // the following will just loop until we get a mock value that equals the required length: + // + while (result == null || result.bitLength() != bitLength) { + result = new BigInteger(bitLength, Random.newInstance()) + } + return result } }