lundi 9 novembre 2020

akka.net Testkit crashing issue c#

Hi, everyone, i am facing an issue while testing one of our top-level actors the adminactor, i currently have two test cases each of them run fine when tested alone but when running the tests together i get an error that is related to the TestKit. and this is the error message recived error message

Here is the name spaces that we use for the test

 using System;
 using AdminErrorQuestion;
 using AdminErrorQuestion.Enumerations;
 using Akka.Actor;
 using Akka.TestKit.NUnit3;
 using FluentAssertions;
 using NUnit.Framework;

 namespace AdminErrorQuestionTests
 {
 [TestFixture]
 public class AdminActorTest : TestKit
 {

This is the first test scenario to check if the andmin actor is receiving the correct IActorRef Message

    [Test]
    public void AdminActor_InConfiguring_ReceivingANullAsTokenManagerRef_AdminActorSchouldStoppAndLogCorrectMessage ()
    {
        // setup fake actors for logger, dbManager
        var dbManager = CreateTestProbe ("dbManager");
        var logger = CreateTestProbe ("logger");

        // create /admin "sut" and hand fakes in; ctor will start processing
        var sut =
            ActorOfAsTestActorRef<AdminErrorQuestion.AdminActor> (Props.Create (() => 
                                                        new AdminErrorQuestion.AdminActor (1,
                                                                                    "system",
                                                                                    logger,
                                                                                    dbManager,
                                                                                    TestActor)),
                                                                  "adminManager");

        // register for watching life of sut
        Watch (sut);

        // expect actor ref req send to security
        ExpectMsg<SecurityActor.GetActorRefReq> (TimeSpan.FromMilliseconds (500));
        var req = (SecurityActor.GetActorRefReq)LastMessage;

        // /security must respond with ActorRef == null
        sut.Tell (new SecurityActor.GetActorRefRsp (req.MessageId, null));

        // check message received by logger
        logger.ExpectMsg<LogActor.LogMessageCmd> (TimeSpan.FromMilliseconds (200));
        var errorMessage = (LogActor.LogMessageCmd)logger.LastMessage;

        // check correct message to log & correct level
        errorMessage.MessageToLog.Should ().Be ("/tokenManager could not be retrieved from /security 
       - stopping");
        errorMessage.Level.Should ().Be (SeverityLevel.Fatal);

        //  wait & check if /admin stopped to confirm the test
        var msg = ExpectMsg<Terminated> (TimeSpan.FromMilliseconds (500));
        msg.ActorRef.Should ().Be (sut);
    }

This is the second test to check if we are receiving the correct CorrectMessage

    [Test]
    public void AdminActor_InConfiguring_ReceivingAWrongMessageId_ShouldLogCorrectMessage ()
    {
        // setup fake actors for logger, dbManager
        var dbManager = CreateTestProbe ("dbManager");
        var logger = CreateTestProbe ("logger");

        // create  /admin "sut" and hand fakes in; ctor will start processing
        var sut =
            ActorOfAsTestActorRef<AdminErrorQuestion.AdminActor> (Props.Create (() => new 
                                                            AdminErrorQuestion.AdminActor (1,
                                                                                    "system",
                                                                                    logger,
                                                                                    dbManager,
                                                                                    TestActor)),
                                                                  "adminManager");

        // expect actor ref req send to security
        ExpectMsg<SecurityActor.GetActorRefReq> (TimeSpan.FromMilliseconds (200));

        // /security must respond with different MessageId than the /tokenManager MessageId
        sut.Tell (new SecurityActor.GetActorRefRsp (Guid.NewGuid (), TestActor));

        // check message received by /logger
        logger.ExpectMsg<LogActor.LogMessageCmd> ();
        var errorMessage = (LogActor.LogMessageCmd)logger.LastMessage;

        // check correct message to log & correct level
        errorMessage.MessageToLog.Should ().Be ("received an out-of-sequence response - dropping 
         it");
        errorMessage.Level.Should ().Be (SeverityLevel.Error);
    }
}

}

Aucun commentaire:

Enregistrer un commentaire