Skip to content
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

Merged
merged 2 commits into from
Sep 18, 2018
Merged

ActorTestKit overhaul, #24598 #25586

merged 2 commits into from
Sep 18, 2018

Conversation

patriknw
Copy link
Member

@patriknw patriknw commented Sep 7, 2018

  • composition is the basic building block for ActorTestKit
  • ActorTestKitWordSpec for integration with ScalaTest
    (automatic shutdown)

I haven't updated existing tests outside akka-actor-testkit-typed, will continue on that next week.

Refs #24598

@akka-ci akka-ci added validating PR is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed validating PR is currently being validated by Jenkins labels Sep 7, 2018
@akka-ci
Copy link

akka-ci commented Sep 7, 2018

Test FAILed.

@patriknw
Copy link
Member Author

@ktoso ready for review, I have pushed latest

@akka-ci akka-ci added validating PR is currently being validated by Jenkins and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) labels Sep 10, 2018
@ktoso
Copy link
Member

ktoso commented Sep 10, 2018

Great, thanks!

@akka-ci akka-ci added tested PR that was successfully built and tested by Jenkins and removed validating PR is currently being validated by Jenkins labels Sep 10, 2018
@akka-ci
Copy link

akka-ci commented Sep 10, 2018

Test PASSed.

@patriknw
Copy link
Member Author

rebased and updated latest

@akka-ci akka-ci added validating PR is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed tested PR that was successfully built and tested by Jenkins validating PR is currently being validated by Jenkins labels Sep 12, 2018
@akka-ci
Copy link

akka-ci commented Sep 12, 2018

Test PASSed.

Copy link
Member

@ktoso ktoso left a 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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth making a ConsistencySpec?

Copy link
Member Author

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)
Copy link
Member

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?

Copy link
Member Author

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))
Copy link
Member

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 :)

Copy link
Member Author

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 {
Copy link
Member

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")
}
}

Copy link
Member

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
Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

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
Copy link
Member

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...

Copy link
Member Author

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

@akka-ci akka-ci added validating PR is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed tested PR that was successfully built and tested by Jenkins validating PR is currently being validated by Jenkins labels Sep 13, 2018
@akka-ci
Copy link

akka-ci commented Sep 13, 2018

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
@patriknw
Copy link
Member Author

Rebased, including @chbatey improvements as separate commit. Don't squash merge.

Copy link
Member

@chbatey chbatey left a 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)
Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

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.
Copy link
Member

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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer extend this

@patriknw
Copy link
Member Author

I can fix those things here

@patriknw
Copy link
Member Author

fixed, used ScalaTestWithActorTestKit but can change to something else if we have better suggestions

@akka-ci akka-ci added validating PR is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed tested PR that was successfully built and tested by Jenkins validating PR is currently being validated by Jenkins labels Sep 17, 2018
@akka-ci
Copy link

akka-ci commented Sep 17, 2018

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 {
Copy link
Member

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

Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member Author

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 ...

Copy link
Member Author

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

@ktoso
Copy link
Member

ktoso commented Sep 18, 2018

Looks good now, nice improvement; Had naming suggestion if you want to give it a shot using that

@patriknw patriknw merged commit 83c7894 into master Sep 18, 2018
@patriknw patriknw deleted the wip-24598-testkit-patriknw branch September 18, 2018 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tested PR that was successfully built and tested by Jenkins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants