vendredi 24 avril 2015

Inconsistent failures on route request in Play FakeRequest

I'm trying to figure out why a play 2.3 test fails inconsistently. I have a spec similar to the following:

val fakeApp = FakeApplication(withGlobal = Some(new MySpecGlobalSettings()))
var paramString:String = _

"MyController" should {
  "generate a parameter" in new WithApplication(fakeApp) {
    val Some(result) = route(FakeRequest(GET, "/myendpoint"))
    status(result) must equalTo(OK)
    paramString = contentAsString(result)
  }

  "accept the string" in new WithApplication(fakeApp) {
    val Some(result) = route(FakeRequest(GET, s"/myendpoint_validator?param=${paramString}")
    status(result) must equalTo(OK)
  }
}

The controller function that handles myendpoint_validator is not complicated - it renders a response based on the param. However, this test now randomly fails about 20% of times it runs:

[info] MyController should
[info] + generate a parameter
[info] ! accept the string
[error]    MatchError: : None (of class scala.None$)  (MyControllerSpec.scala:11)
[error] MyControllerSpec$$anonfun$11$$anonfun$apply$4$$anon$2$delayedInit$body.apply(MyControllerSpec.scala:11)

Line 11 is the "accept the string" line in the spec...

Any ideas why the test randomly throws this error?

Aucun commentaire:

Enregistrer un commentaire