orleans icon indicating copy to clipboard operation
orleans copied to clipboard

Unit Testing & OrleansTestKit Path Forward

Open dsarfati opened this issue 8 years ago • 2 comments

We have been discussing our testing strategy internally and would like to see if anyone else has opinions on how we can make testing better in Orleans. We are thinking about using a similar API to the one I created in OrleansTestKit, but run it within the actual Orleans runtime. The OrleansTestKit is able to run tests for many simple use cases, however it will not support more complex grain that are deeply integrated with Orleans for example, Lifecycle events. There are many other things that Orleans does that would not be able to be tested inside the TestKit. Rather than spending more time emulating Orleans behaviors, we are thinking about a new approach that would allow the same assertions that exist within the current TestKit, but would allow grain code to execute exactly as it does when running in a real silo.

In reality, most of this proposal is just to allow developers to assert grain state, grain calls to other grains, and provide a way for a developer configure a mock grain that will return the desired value or exception when a grain is called.

What would need to be built:

Storage provider

  • Assert the current grain state
  • Setup the grain state prior to activation

Stream provider

  • Assert that a grain is subscribed to a specific stream
  • Assert that a grain sends the proper message on a stream
  • Assert that a grain received a message from a stream without error
  • Assert that a grain unsubscribed from a specific stream

Reminder Provider

  • Assert that a reminder was registered for the correct time
  • Fire a reminder on demand from within a test

Mock Grain Call Filter

  • Assert that another grain was called with the correct values
  • Intercept grain-to-grain method calls and return a specific value or throw an exception

Other

  • Deactivate a grain on demand
  • Activate a grain on demand

Please let me know if you have other things that you would like exposed and we can talk about a roadmap to build out these features. We are going to start prototyping some of these behaviors this week to see how they work in practice.

dsarfati avatar Apr 30 '18 18:04 dsarfati

Hi, I'm currently running Orleans 1.5.2 component tests using TestCluster, and their purpose is to test the E2E Orleans flow and related scenarios, taking the BDD approach, e.g. a grain runs some external table query every 10 seconds (grain uses timer, but test doesn't care). These are not unit tests, but I do fake the behavior of my own interfaces injected to grains since I want to test just the Orleans related aspects, not my own business logic classes. The issue here is that the tests run in an AppDomain that is separated from the grains, so I can't create a mock (e.g. using Moq) in the test and have it injected to grains, at least in a simple manner. Currently I'm creating new grains for testing to serve as mocks, by injecting to grains implementations to my interfaces that proxy calls to the new mock grains, which the test can then setup/query. This approach requires a lot of boilerplate and verbosity which libraries like Moq spare me of, so I'd very interested in a solution that will enable me simple integration with mocking libraries, leveraging Orleans DI support to do so.

Eldar1205 avatar Jun 01 '18 08:06 Eldar1205

Just an idea, under Stream Provider. A oleans client can (un)subscribe from a stream, produce or receive message from a stream too. Is it helpful to add assertion on those?

xiazen avatar Jun 08 '18 22:06 xiazen