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

TestJournal and TestSnaphostStore #3881

Merged
merged 24 commits into from
Aug 31, 2019

Conversation

valdisz
Copy link
Contributor

@valdisz valdisz commented Aug 8, 2019

PR addresses issue #3877

Added 3 new projects:

  • Akka.Persistence.TestKit
  • Akka.Persistence.TestKit.Tests
  • Akka.Persistence.TestKit.Xunit2

It adds a new journal (TestJournal) and a new snapshot store (TestSnaphostStore). It is possible to intercept calls to them and apply user-defined behavior, i.e. to simulate network problems or anything else.

It adds new test base class PersistenceTestKit (Xunit2 based) to simplify usage. API loos like this:

public class PersistentActorSpec : PersistenceTestKit
{
    [Fact]
    public async Task actor_must_fail_when_journal_will_fail_saving_message()
    {
        await WithJournalWrite(write => write.Fail(), () =>
        {
            var actor = ActorOf(() => new PersistActor());
            Watch(actor);

            actor.Tell("write", TestActor);
            ExpectTerminated(actor);
        });
    }
}

@valdisz valdisz changed the title Feedback needed on feature addressing issue #3877 Feedback needed on feature addressing specialised Test Journal Aug 8, 2019
@Aaronontheweb
Copy link
Member

Build failed due to TestJournalSpec.cs(28,13): error CS0165: Use of unassigned local variable 'journal' [D:\a\1\s\src\core\Akka.Persistence.TestKit.Tests\Akka.Persistence.TestKit.Tests.csproj]

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

I know this is a very early preview and you have more iterations you're working on, but I wanted to pass along some comments.

@valdisz valdisz force-pushed the feature/persistence-testkit branch 2 times, most recently from d0aa37f to f640b69 Compare August 9, 2019 21:40
@valdisz valdisz force-pushed the feature/persistence-testkit branch from f640b69 to 46c77c4 Compare August 9, 2019 21:49
Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

Looking good so far - I think we should add a new base class on top of the TestKitBase that makes it more concise to use some of these Journal failure methods when writing a test, The underlying TestJournal itself looks great though.

src/core/Akka.Persistence.TestKit/JournalInterceptors.cs Outdated Show resolved Hide resolved
src/core/Akka.Persistence.TestKit/JournalInterceptors.cs Outdated Show resolved Hide resolved
src/core/Akka.Persistence.TestKit/JournalInterceptors.cs Outdated Show resolved Hide resolved
src/core/Akka.Persistence.TestKit/TestJournal.cs Outdated Show resolved Hide resolved
src/core/Akka.Persistence.TestKit/TestJournal.cs Outdated Show resolved Hide resolved
src/core/Akka.Persistence.TestKit/TestJournal.cs Outdated Show resolved Hide resolved
@valdisz valdisz changed the title Feedback needed on feature addressing specialised Test Journal TestJournal and TestSnaphostStore Aug 11, 2019
@valdisz
Copy link
Contributor Author

valdisz commented Aug 11, 2019

@Aaronontheweb I have implemented PersistenceTestKit. Is it what you were expecting?

@valdisz
Copy link
Contributor Author

valdisz commented Aug 12, 2019

One test in a totally different project (which was not modified) is failing. No idea why.

@Aaronontheweb
Copy link
Member

@valdisz we have a number of test failures that are due to concurrent tests with hard deadlines blocking threads, We have an open proposal to fix this by moving everything to an async / await model in #3854 - we're going to have to address it in a future release. Don't worry about it for the time being.

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

Have some more comments I want to add, but I need to do some work with this code locally on my machine first.

src/core/Akka.Persistence.TestKit/PersistenceTestKit.cs Outdated Show resolved Hide resolved
Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

Added some examples of the type of functionality I'd like to see built into the PersistentTestkit class, and some recommendations on moving away from blocking threads and towards async / await implementations

src/core/Akka.Persistence.TestKit.Tests/TestJournalSpec.cs Outdated Show resolved Hide resolved
src/core/Akka.Persistence.TestKit/PersistenceTestKit.cs Outdated Show resolved Hide resolved
src/core/Akka.Persistence.TestKit/PersistenceTestKit.cs Outdated Show resolved Hide resolved
src/core/Akka.Persistence.TestKit/JournalWriteBehavior.cs Outdated Show resolved Hide resolved
@Aaronontheweb
Copy link
Member

@valdisz this is looking good - what are next steps for implementing this? More overloads on the PersistenceTestKit class?

@valdisz
Copy link
Contributor Author

valdisz commented Aug 13, 2019

@Aaronontheweb more unit tests for existing code (some are still needed), then SnaphsotStore and then XML DOC.

@valdisz valdisz force-pushed the feature/persistence-testkit branch from 7ed6cef to aceb9aa Compare August 14, 2019 06:27
Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

This looks great - have some minor changes we need to address (left comments for them) but otherwise I think this is ready to go.

We'll work on getting documentation added to the website for this built into a separate pull request and we'll also plan on releasing this as part of the v1.4.0-beta2 launch, so users can start using it and giving us some feedback. We'll probably consume it inside the Akka.Persistence.Extras project as a starting point.

/// This class represents an Akka.NET Persistence TestKit that uses <a href="https://xunit.github.io/">xUnit</a>
/// as its testing framework.
/// </summary>
public abstract class PersistenceTestKit : PersistenceTestKitBase
Copy link
Member

Choose a reason for hiding this comment

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

Need to add a constructor overload here which takes an ITestOutputHelper for XUnit - that's how we're able to inject the XUnit output capture system into the Akka.NET logging infrastructure. Here's an example of a unit test where a user would do that:

https://github.com/akkadotnet/akka.net/blob/dev/src/core/Akka.Remote.Tests/RemotingSpec.cs#L31

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To correctly handle ITestOutputHelper in test kit I changed the base class of PersistenceTestKit to TestKit. This means that PersistenceTestKitBase no longer exists other test frameworks will not have Test Kit class with persistence testing API out of the box for now.

@valdisz valdisz marked this pull request as ready for review August 23, 2019 09:03
@valdisz
Copy link
Contributor Author

valdisz commented Aug 23, 2019

PR is ready, all work is done. If any issues are found, please comment, otherwise, merge.

@Danthar
Copy link
Member

Danthar commented Aug 25, 2019

We got some errors in Tests, in the MNTK tests related to persistence are failing with casting errors. However as far as i can tell that should not be code this PR changed.

Did we change an IList to an SortedSet somewhere in this PR ?

@valdisz
Copy link
Contributor Author

valdisz commented Aug 25, 2019

We got some errors in Tests, in the MNTK tests related to persistence are failing with casting errors. However as far as i can tell that should not be code this PR changed.

Did we change an IList to an SortedSet somewhere in this PR ?

This PR does not change anything except adding 3 new projects to the solution.
For me, it is hard to guess why that particular test failed.
I can dig in, but that will take some time.

@Danthar
Copy link
Member

Danthar commented Aug 25, 2019 via email

@Danthar
Copy link
Member

Danthar commented Aug 26, 2019

Think i found the issue. Problem happens during json serialization/deserialization. Im thinking this PR is the culprit #3671 Because i cannot find anything else that might cause this.

@valdisz
Copy link
Contributor Author

valdisz commented Aug 26, 2019

Surprisingly my next PR does not fail any builds. #3889

@Danthar
Copy link
Member

Danthar commented Aug 26, 2019 via email

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

LGTM

@Aaronontheweb
Copy link
Member

I'll take a look at that failing spec - I think it's due to the JSON.NET upgrade. CI didn't run because I think the common.props file was the only thing that was upgraded. Incrementalist will need to be upgraded to detect that a shared project property file changed.

@Aaronontheweb
Copy link
Member

#3892

@Aaronontheweb
Copy link
Member

Having a persistent failure with MNTR specs on .NET Framework only:

##teamcity[testFailed name='Akka.Cluster.Tools.Tests.MultiNode.PublishSubscribe.DistributedPubSubMediatorSpec.DistributedPubSubMediatorSpecs' message='|[NODE2:second|]|[12:33 PM|]: SPEC FAILED: Akka.Cluster.Tools.Tests.MultiNode.PublishSubscribe.DistributedPubSubMediatorSpec.DistributedPubSubMediatorSpecs|r FAIL' details='' timestamp='2019-08-27T12:33:42.162+0000' flowId='11']
[INFO][8/27/2019 12:33:42 PM][Thread 0003][[akka://TestRunnerLogging/user/TcpLogger#1268474739]] Node disconnected on [akka://TestRunnerLogging/system/IO-TCP/$a/$o#557351663]

Unknown message: Node\PublishSubscribe\DistributedPubSubMediatorSpec.cs:line 751
   at Akka.Cluster.Tools.Tests.MultiNode.PublishSubscribe.DistributedPubSubMediatorSpec.<DistributedPubSubMediator_must_remove_entries_when_node_is_removed>b__39_0() in D:\a\1\s\src\contrib\cluster\Akka.Cluster.Tools.Tests.MultiNode\PublishSubscribe\DistributedPubSubMediatorSpec.cs:line 752
   at Akka.TestKit.TestKitBase.<>c__DisplayClass141_0.<Within>b__0() in D:\a\1\s\src\core\Akka.TestKit\TestKitBase_Within.cs:line 48
   at Akka.TestKit.T
Unknown message: estKitBase.Within[T](TimeSpan min, TimeSpan max, Func`1 function, String hint, Nullable`1 epsilonValue) in D:\a\1\s\src\core\Akka.TestKit\TestKitBase_Within.cs:line 101
   at Akka.TestKit.TestKitBase.Within(TimeSpan min, TimeSpan max, Action action, String hint, Nullable`1 epsilonValue) in D:\a\1\s\src\core\Akka.TestKit\TestKitBase_Within.cs:line 49
   at Akka.TestKit.TestKitBase.Within(TimeSpan max, Action action, Nullable`1 epsilonValue) in D:\a\1\s\src\core\Akka.TestKit\TestKitBase_Within.cs:line 32
 
Unknown message:   at Akka.Cluster.Tools.Tests.MultiNode.PublishSubscribe.DistributedPubSubMediatorSpec.DistributedPubSubMediator_must_remove_entries_when_node_is_removed() in D:\a\1\s\src\contrib\cluster\Akka.Cluster.Tools.Tests.MultiNode\PublishSubscribe\DistributedPubSubMediatorSpec.cs:line 761
   at Akka.Cluster.Tools.Tests.MultiNode.PublishSubscribe.DistributedPubSubMediatorSpec.DistributedPubSubMediatorSpecs() in D:\a\1\s\src\contrib\cluster\Akka.Cluster.Tools.Tests.MultiNode\PublishSubscribe\DistributedPubSubMediato
Unknown message: nToken) in D:\a\1\s\src\core\Akka\Actor\Futures.cs:line 128

##teamcity[testFailed name='Akka.Cluster.Tools.Tests.MultiNode.PublishSubscribe.DistributedPubSubMediatorSpec.DistributedPubSubMediatorSpecs' message='|[NODE1:first|]|[12:33 PM|]: SPEC FAILED: Akka.Cluster.Tools.Tests.MultiNode.PublishSubscribe.DistributedPubSubMediatorSpec.DistributedPubSubMediatorSpecs|r FAIL' details='' timestamp='2019-08-27T12:33:47.471+0000' flowId='11']
##teamcity[testFailed name='Akka.Cluster.Tools.Tests.MultiNode.PublishSubscribe.DistributedPubSubMediatorSpec.DistributedPubSubMediatorSpecs' message='|[NODE1:first|]|[12:33 PM|]: SPEC FAILED: Message: Timeout after 00:00:05 seconds|r' details='' timestamp='2019-08-27T12:33:47.471+0000' flowId='11']
##teamcity[testFailed name='Akka.Cluster.Tools.Tests.MultiNode.PublishSubscribe.DistributedPubSubMediatorSpec.DistributedPubSubMediatorSpecs' message='|[NODE1:first|]|[12:33 PM|]: SPEC FAILED: StackTrace:    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)|r' details='' timestamp='2019-08-27T12:33:47.471+0000' flowId='11']
##teamcity[testFailed name='Akka.Cluster.Tools.Tests.MultiNode.PublishSubscribe.DistributedPubSubMediatorSpec.DistributedPubSubMediatorSpecs' message='|[NODE1:first|]|[12:33 PM|]: SPEC FAILED: StackTrace:    at Akka.Actor.Futures.Ask(ICanTell self, Func`2 messageFactory, IActorRefProvider provider, Nullable`1 timeout, CancellationToken cancellationToken) in D:\a\1\s\src\core\Akka\Actor\Futures.cs:line 187|r' details='' timestamp='2019-08-27T12:33:47.471+0000' flowId='11']

Going to take a closer look at this - don't think it's related to these changes.

@Aaronontheweb Aaronontheweb merged commit 37be6a5 into akkadotnet:dev Aug 31, 2019
@valdisz valdisz deleted the feature/persistence-testkit branch September 22, 2019 20:01
Aaronontheweb pushed a commit to Aaronontheweb/akka.net that referenced this pull request Sep 23, 2019
* TestJournal with Write interception and various failure strategies
* Akka.Persistence.TestKit implementation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants