Specs2 await 不会在范围内失败
Specs2 await doesn't fail inside of a Scope
当使用 Specs2(v 2.3.13) await 时,我注意到在某些情况下它不会失败。具体来说,我观察到如果 "await" 在范围内超时,那么它不会失败。
"Awaiting a failed future should fail" in {
Future.failed(throw new Exception()).map(_ => success).await // Fails Correctly
}
"Awaiting a timed out future should fail" in {
Future(Thread.sleep(5000)).map(_ => success).await // Fails Correctly
}
"Awaiting a failed scope should fail" in new Scope {
failure // Fails Correctly
}
"Awaiting a failed future in a scope should fail" in new Scope {
Future.failed(throw new Exception()).map(_ => success).await // Fails Correctly
}
"Awaiting a timed out future in a scope should fail" in new Scope {
Future(Thread.sleep(5000)).map(_ => success).await // DOES NOT FAIL
}
是我误解了用法,还是这是一个错误?
隐含在 Future[T]
上的 .await
只会创建一个 Result
,如果超时,它将失败。但是不会抛出任何异常,因此结果不会逃脱 Scope
特征。
要解决此问题,您需要使用 Matchers
并在 Future[T]
:
中指定您对类型 T
的期望值
Future(Thread.sleep(5000)).map(_ => 1) must be_==(1).await
这将正确显示
[info] x Awaiting a timed out future in a scope should fail
[error] Timeout after 1 second (TestSpec.scala:35)
当使用 Specs2(v 2.3.13) await 时,我注意到在某些情况下它不会失败。具体来说,我观察到如果 "await" 在范围内超时,那么它不会失败。
"Awaiting a failed future should fail" in {
Future.failed(throw new Exception()).map(_ => success).await // Fails Correctly
}
"Awaiting a timed out future should fail" in {
Future(Thread.sleep(5000)).map(_ => success).await // Fails Correctly
}
"Awaiting a failed scope should fail" in new Scope {
failure // Fails Correctly
}
"Awaiting a failed future in a scope should fail" in new Scope {
Future.failed(throw new Exception()).map(_ => success).await // Fails Correctly
}
"Awaiting a timed out future in a scope should fail" in new Scope {
Future(Thread.sleep(5000)).map(_ => success).await // DOES NOT FAIL
}
是我误解了用法,还是这是一个错误?
隐含在 Future[T]
上的 .await
只会创建一个 Result
,如果超时,它将失败。但是不会抛出任何异常,因此结果不会逃脱 Scope
特征。
要解决此问题,您需要使用 Matchers
并在 Future[T]
:
T
的期望值
Future(Thread.sleep(5000)).map(_ => 1) must be_==(1).await
这将正确显示
[info] x Awaiting a timed out future in a scope should fail
[error] Timeout after 1 second (TestSpec.scala:35)