在CI服务器上运行的SBTtesting非常慢
我在Bitbucket上有一个CIpipe道设置并运行
sbt "project api" "testOnly core.entities.UserSpec"
它在我的笔记本电脑上运行平稳,耗时约2秒。 但是当我尝试在CI服务器上运行它时,花了大约4分钟来运行一半的testing。
UserSpec用Spec2编写,没有任何数据库或大量计算。 这里的大部分testing是这样的:
def addCredential_nonConfirmedEmail_notAllowed = { val emailAddress: EmailAddress = Fixture.emailAddress("unconfirmed") val user: User = Fixture.user().copy(emailAddresses = Set(emailAddress)) val result = user.addCredential(emailAddress, Fixture.password()) val exception = result.failed.get.asInstanceOf[DomainException] exception.code mustEqual DomainExceptionType.Validation exception.message mustEqual "Email address must be confirmed before it can be used as part of credential" }
CI使用“bigtruedata / sbt:0.13.15-2.11.11”图像在Docker上运行。 为了解决这个问题,我在墙上敲了两天。 首先,我责备CI并尝试:
- gitlab ci
- wercker
仍然没有运气。
你能帮我解决这个问题吗? 这是我的sbt设置的样子
val projectSettings = Seq( version := "1.0-SNAPSHOT", scalaVersion := "2.11.11", resolvers ++= Dependencies.resolvers, fork in Test := false, parallelExecution in Test := false)
最后,我find了罪魁祸首! 这是我,而不是CI,docker或SBT。
我在testing中使用了SecureRandom.getInstanceStrong中的val salt = BCrypt.gensalt(10, SecureRandom.getInstanceStrong)
()方法,如val salt = BCrypt.gensalt(10, SecureRandom.getInstanceStrong)
。 根据这个参考,如果没有足够的随机性会阻塞线程。 一旦我删除SecureRandom.getInstanceStrong
,它现在正常工作。
在使用之前,我应该学会Random和SecureRandom之间的差异,并因此浪费了3天时间。 很难学习:–D