-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ActorTestKit overhaul, #24598 #25586
Conversation
Test FAILed. |
7dffdd6
to
ced0147
Compare
@ktoso ready for review, I have pushed latest |
Great, thanks! |
Test PASSed. |
ced0147
to
fd913a8
Compare
rebased and updated latest |
Test PASSed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking honestly very nice :)
Like that we keep our small helper one and the keeping kit as val is also nice for people... Thanks for doing this big refactor!
|
||
import scala.util.control.NoStackTrace | ||
|
||
class TestException(msg: String) extends RuntimeException(msg) with NoStackTrace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some quick docs for it since it may show up in our examples etc?
@@ -157,6 +174,8 @@ final class ActorTestKit protected (delegate: akka.actor.testkit.typed.scaladsl. | |||
*/ | |||
def createTestProbe[M](name: String, clazz: Class[M]): TestProbe[M] = TestProbe.create(name, clazz, system) | |||
|
|||
// Note that if more methods are added here they should also be added to TestKitJunitResource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worth making a ConsistencySpec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not worth it here, I think. The bulk of methods shouldn't be added here, but in the TestProbe
* Shortcut for creating a new test probe for the testkit actor system | ||
* @tparam M the type of messages the probe should accept | ||
*/ | ||
def createTestProbe[M](): TestProbe[M] = TestProbe()(system) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on purpose not spawn here I guess... really sure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's good to reserve spawn for real actors, a TestProbe is not an actor, it has a ref and much else
* `PatienceConfig` from [[akka.actor.testkit.typed.TestKitSettings#DefaultTimeout]] | ||
*/ | ||
implicit val patience: PatienceConfig = | ||
PatienceConfig(testKit.testKitSettings.DefaultTimeout.duration, Span(100, org.scalatest.time.Millis)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically maybe also as config...? though I guess maybe "until people ask for it" is fine here; ignore this request :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, and one can override the val
if something special is needed
* `testKit.shutdownTestKit()`. | ||
*/ | ||
abstract class ActorTestKitWordSpec(testKit: ActorTestKit) extends ActorTestKitBase(testKit) | ||
with WordSpecLike with Matchers with BeforeAndAfterAll with ScalaFutures with Eventually { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's good enough... If people want different things they can copy this one and e.g. change to FlatSpec or whatnot
testKit.system.name should ===("CompositionSpec") | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool and also usable as docs snippet I suppose
} | ||
} | ||
} | ||
//#scalatest-integration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok so that's used as the example snippet, good
have the async test kit automatically shutdown when the test is complete. | ||
|
||
Note that the dependency on ScalaTest is marked as optional from the test kit module, so your project must explicitly include | ||
a dependency on ScalaTest to use this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was thinking if we should include which version at least... but that will be a hassle to maintain so nah
@@ -132,6 +132,9 @@ object Dependencies { | |||
|
|||
val junit = Compile.junit % "optional;provided;test" | |||
|
|||
|
|||
val scalatest = Def.setting { "org.scalatest" %% "scalatest" % scalaTestVersion.value % "optional;provided;test" } // ApacheV2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dep / provided looks good... 👍 Did we sanity check what ends up in POM so we don't accidentally do it wrong?
AFAIR some of the scopes sometimes work weird...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it becomes:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.12</artifactId>
<version>3.0.5</version>
<scope>test</scope>
<optional>true</optional>
</dependency>
which I guess is fine
fd913a8
to
debe122
Compare
Test PASSed. |
* composition is the basic building block for ActorTestKit * ActorTestKitWordSpec for integration with ScalaTest (automatic shutdown) * Use ActorTestKitWordSpec in our own tests * doc TestException
0a700d5
to
501a893
Compare
Rebased, including @chbatey improvements as separate commit. Don't squash merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few doc things that could be done now or in a follow up as this is conflict central!
LGTM
* Note that ScalaTest is not provided as a transitive dependency of the testkit module but must be added explicitly | ||
* to your project to use this. | ||
*/ | ||
abstract class ActorTestKitScalaTestSpec(testKit: ActorTestKit) extends ActorTestKitBase(testKit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is quite a long name, should we drop Spec at the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
ActorTestKitScalaTest
is also stacking a lot of words together and it might be difficult to see that it is about mixing ActorTestKit and ScalaTest. Perhaps ActorTestKitWithScalaTest
, or ScalaTestWithActorTestKit
.
The latter is perhaps more correct
@@ -212,16 +215,19 @@ a dependency on JUnit to use this. | |||
|
|||
@@@ div { .group-scala } | |||
|
|||
It often makes sense to introduce a common base class for all tests using the async test kit, here is an example how to | |||
hook it into a ScalaTest test suite. | |||
If you are using ScalaTest you can extend `akka.actor.testkit.typed.scaladsl.ActorTestKitWordSpec` to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs updating now, i missed that in my branch
It often makes sense to introduce a common base class for all tests using the async test kit, here is an example how to | ||
hook it into a ScalaTest test suite. | ||
If you are using ScalaTest you can extend `akka.actor.testkit.typed.scaladsl.ActorTestKitWordSpec` to | ||
have the async test kit automatically shutdown when the test is complete. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add in about overriding afterAll?
|
||
Java | ||
: @@snip [AsyncTestingExampleTest.java](/akka-actor-testkit-typed/src/test/java/akka/actor/testkit/typed/javadsl/AsyncTestingExampleTest.java) { #under-test } | ||
: @@snip [AsyncTestingExampleTest.java](/akka-actor-testkit-typed/src/test/java/jdocs/akka/actor/testkit/typed/javadsl/AsyncTestingExampleTest.java) { #under-test } | ||
|
||
@scala[Tests extend `ActorTestKit`. This provides access to]@java[Tests create an instance of `ActorTestKit`. This provides access to] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer extend this
I can fix those things here |
501a893
to
1d0603d
Compare
fixed, used |
Test PASSed. |
abstract class ActorTestKitWordSpec(testKit: ActorTestKit) extends ActorTestKitBase(testKit) | ||
with WordSpecLike with Matchers with BeforeAndAfterAll with ScalaFutures with Eventually { | ||
abstract class ScalaTestWithActorTestKit(testKit: ActorTestKit) extends ActorTestKitBase(testKit) | ||
with TestSuite with Matchers with BeforeAndAfterAll with ScalaFutures with Eventually { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice change, since some people may want FlatSpec
etc 👍
Name I'd consider using the *Support naming we have in some places in akka http; like "ScalaTestActorTestKitSupport"? If you want to keep though then I can live with this one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think "support" adds much information. Happy with current.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another alternative was to put it in a scalatest package and just call it ActorTestKitSupport
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my intention of using the separator With
word was to see which parts are together. ScalaTest ActorTestKit or is it Scala TestActor TestkKit or ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming, I'll just merge this now
Looks good now, nice improvement; Had naming suggestion if you want to give it a shot using that |
(automatic shutdown)
I haven't updated existing tests outside
akka-actor-testkit-typed
, will continue on that next week.Refs #24598