public void SpecRunCoordinator_should_mark_spec_as_passed_if_all_nodes_pass()
        {
            var nodeIndexes = Enumerable.Range(1, 3).ToArray();
            var nodeTests   = NodeMessageHelpers.BuildNodeTests(nodeIndexes);

            var specRunCoordinator = Sys.ActorOf(Props.Create(() => new SpecRunCoordinator(nodeTests.First()
                                                                                           .TypeName, nodeTests.First().MethodName, nodeTests)));

            var messages = NodeMessageHelpers.GenerateMessageSequence(nodeIndexes, 100);

            //Add some result (PASS) messages
            messages.UnionWith(NodeMessageHelpers.GenerateResultMessage(nodeIndexes, true));

            foreach (var multiNodeMessage in messages)
            {
                specRunCoordinator.Tell(multiNodeMessage);
            }

            //End the test
            specRunCoordinator.Tell(new EndSpec(), TestActor);
            var factData = ExpectMsg <FactData>();

            Assert.Equal(nodeIndexes.Length, factData.NodeFacts.Count);
            Assert.True(factData.NodeFacts.All(x => x.Value.Passed.Value), "each individual node should have marked their test as passed");
            Assert.True(factData.Passed.Value, "SpecCoordinator should have marked spec as passed");
        }
        public void NodeData_should_process_LogMessageFragments_into_timeline()
        {
            var nodeIndex     = 1;
            var nodeDataActor = Sys.ActorOf(Props.Create(() => new NodeDataActor(nodeIndex)));
            var m1            = NodeMessageHelpers.GenerateMessageSequence(nodeIndex, 3);

            foreach (var m in m1)
            {
                nodeDataActor.Tell(m);
            }

            var m2 = NodeMessageHelpers.GenerateMessageFragmentSequence(nodeIndex, 4);

            foreach (var m in m2)
            {
                nodeDataActor.Tell(m);
            }

            //union the two sets together
            m1.UnionWith(m2);

            //Kill the node data actor and have it deliver its payload to TestActor
            nodeDataActor.Tell(new EndSpec(), TestActor);

            var nodeData = ExpectMsg <NodeData>();

            Assert.True(m1.SetEquals(nodeData.EventStream));
            Assert.Equal(nodeIndex, nodeData.NodeIndex);
            Assert.False(nodeData.EndTime.HasValue);
            Assert.False(nodeData.Passed.HasValue);
        }
        public void SpecRunCoordinator_should_route_messages_correctly_to_child_NodeDataActors()
        {
            var nodeIndexes = Enumerable.Range(1, 3).ToArray();
            var nodeTests   = NodeMessageHelpers.BuildNodeTests(nodeIndexes);

            var specRunCoordinator = Sys.ActorOf(Props.Create(() => new SpecRunCoordinator(nodeTests.First()
                                                                                           .TypeName, nodeTests.First().MethodName, nodeTests)));

            var messages = NodeMessageHelpers.GenerateMessageSequence(nodeIndexes, 100);

            foreach (var multiNodeMessage in messages)
            {
                specRunCoordinator.Tell(multiNodeMessage);
            }

            //End the test
            specRunCoordinator.Tell(new EndSpec(), TestActor);
            var factData = ExpectMsg <FactData>();

            // Combine the messages from each individual NodeData back into a unioned set.
            // Should match what we sent (messages.)
            var combinedTimeline = new SortedSet <MultiNodeMessage>();

            foreach (var nodeData in factData.NodeFacts)
            {
                combinedTimeline.UnionWith(nodeData.Value.EventStream);
            }

            Assert.Equal(nodeIndexes.Length, factData.NodeFacts.Count);
            Assert.True(messages.SetEquals(combinedTimeline));
        }
        public void SpecRunCoordinator_should_mark_spec_as_failed_if_one_node_fails()
        {
            var nodeIndexes = Enumerable.Range(1, 3).ToArray();
            var nodeTests   = NodeMessageHelpers.BuildNodeTests(nodeIndexes);

            var specRunCoordinator = Sys.ActorOf(Props.Create(() => new SpecRunCoordinator(nodeTests.First()
                                                                                           .TypeName, nodeTests.First().MethodName, nodeTests)));

            var messages = NodeMessageHelpers.GenerateMessageSequence(nodeIndexes, 100);

            //Add some result (1 FAIL, 2 PASS) messages
            var front           = nodeIndexes.First();
            var nodesMinusFront = nodeIndexes.Where(x => x != front);

            messages.UnionWith(NodeMessageHelpers.GenerateResultMessage(nodesMinusFront, true)); //PASS messages
            messages.UnionWith(NodeMessageHelpers.GenerateResultMessage(front, false));          //one FAIL message

            foreach (var multiNodeMessage in messages)
            {
                specRunCoordinator.Tell(multiNodeMessage);
            }

            //End the test
            specRunCoordinator.Tell(new EndSpec(), TestActor);
            var factData = ExpectMsg <FactData>();

            Assert.Equal(nodeIndexes.Length, factData.NodeFacts.Count);
            Assert.True(factData.NodeFacts.Count(x => !x.Value.Passed.Value) == 1, "one node should have marked their test as failed");
            Assert.True(factData.NodeFacts.Count(x => x.Value.Passed.Value) == nodeIndexes.Length - 1, "rest of nodes should have marked their test as passed");
            Assert.False(factData.Passed.Value, "SpecCoordinator should have marked spec as failed");
        }
        public void TestCoordinatorEnabledMessageSink_should_receive_TestRunTree_when_EndTestRun_is_received()
        {
            var consoleMessageSink = Sys.ActorOf(Props.Create(() => new ConsoleMessageSinkActor(true)));
            var nodeIndexes        = Enumerable.Range(1, 4).ToArray();
            var nodeTests          = NodeMessageHelpers.BuildNodeTests(nodeIndexes);

            var beginSpec = new BeginNewSpec(nodeTests.First().TypeName, nodeTests.First().MethodName, nodeTests);

            consoleMessageSink.Tell(beginSpec);

            // create some messages for each node, the test runner, and some result messages
            // just like a real MultiNodeSpec
            var allMessages    = NodeMessageHelpers.GenerateMessageSequence(nodeIndexes, 300);
            var runnerMessages = NodeMessageHelpers.GenerateTestRunnerMessageSequence(20);
            var passMessages   = NodeMessageHelpers.GenerateResultMessage(nodeIndexes, true);

            allMessages.UnionWith(runnerMessages);
            allMessages.UnionWith(passMessages);

            foreach (var message in allMessages)
            {
                consoleMessageSink.Tell(message);
            }

            //end the spec
            consoleMessageSink.Tell(new EndSpec());

            //end the test run...
            var sinkReadyToTerminate =
                consoleMessageSink.AskAndWait <MessageSinkActor.SinkCanBeTerminated>(new EndTestRun(),
                                                                                     TimeSpan.FromSeconds(3));

            Assert.NotNull(sinkReadyToTerminate);
        }
        public void NodeData_should_mark_as_failed_when_MultiNodeResultMessage_received()
        {
            var nodeIndex     = 1;
            var nodeRole      = NodeMessageHelpers.DummyRoleFor + nodeIndex;
            var nodeDataActor = Sys.ActorOf(Props.Create(() => new NodeDataActor(nodeIndex, nodeRole)));

            var m1 = NodeMessageHelpers.GenerateMessageSequence(nodeIndex, 3);

            m1.UnionWith(NodeMessageHelpers.GenerateResultMessage(nodeIndex, false));

            foreach (var m in m1)
            {
                nodeDataActor.Tell(m);
            }

            //Kill the node data actor and have it deliver its payload to TestActor
            nodeDataActor.Tell(new EndSpec(), TestActor);

            var nodeData = ExpectMsg <NodeData>();

            Assert.True(m1.SetEquals(nodeData.EventStream));
            Assert.False(nodeData.Passed.Value);
            Assert.True(nodeData.EndTime.HasValue);
            Assert.True(nodeData.EndTime.Value >= nodeData.StartTime);
        }
        public void TestRunCoordinator_should_start_and_route_messages_to_SpecRunCoordinator()
        {
            var testRunCoordinator = Sys.ActorOf(Props.Create <TestRunCoordinator>());
            var nodeIndexes        = Enumerable.Range(1, 4).ToArray();
            var nodeTests          = NodeMessageHelpers.BuildNodeTests(nodeIndexes);

            var beginSpec = new BeginNewSpec(nodeTests.First().TypeName, nodeTests.First().MethodName, nodeTests);

            //begin a new spec
            testRunCoordinator.Tell(beginSpec);

            // create some messages for each node, the test runner, and some result messages
            // just like a real MultiNodeSpec
            var allMessages    = NodeMessageHelpers.GenerateMessageSequence(nodeIndexes, 300);
            var runnerMessages = NodeMessageHelpers.GenerateTestRunnerMessageSequence(20);

            allMessages.UnionWith(runnerMessages);

            foreach (var message in allMessages)
            {
                testRunCoordinator.Tell(message);
            }

            //end the spec
            testRunCoordinator.Tell(new EndTestRun(), TestActor);
            var testRunData = ExpectMsg <TestRunTree>();

            Assert.Equal(1, testRunData.Specs.Count());

            var specMessages = new SortedSet <MultiNodeMessage>();

            foreach (var spec in testRunData.Specs)
            {
                specMessages.UnionWith(spec.RunnerMessages);
                foreach (var fact in spec.NodeFacts)
                {
                    specMessages.UnionWith(fact.Value.EventStream);
                }
            }

            Assert.True(allMessages.SetEquals(specMessages));
        }
        public void SpecRunCoordinator_should_log_TestRunner_messages()
        {
            var nodeIndexes = Enumerable.Range(1, 3).ToArray();
            var nodeTests   = NodeMessageHelpers.BuildNodeTests(nodeIndexes);

            var specRunCoordinator = Sys.ActorOf(Props.Create(() => new SpecRunCoordinator(nodeTests.First()
                                                                                           .TypeName, nodeTests.First().MethodName, nodeTests)));

            var runnerMessages = NodeMessageHelpers.GenerateTestRunnerMessageSequence(100);

            foreach (var multiNodeMessage in runnerMessages)
            {
                specRunCoordinator.Tell(multiNodeMessage);
            }

            //End the test
            specRunCoordinator.Tell(new EndSpec(), TestActor);
            var factData = ExpectMsg <FactData>();

            Assert.True(factData.RunnerMessages.Any());
            Assert.True(runnerMessages.SetEquals(factData.RunnerMessages));
        }
        public void TestRunCoordinator_should_publish_FactData_to_Subscribers_when_Specs_complete()
        {
            var testRunCoordinator = Sys.ActorOf(Props.Create <TestRunCoordinator>());
            var nodeIndexes        = Enumerable.Range(1, 4).ToArray();
            var nodeTests          = NodeMessageHelpers.BuildNodeTests(nodeIndexes);

            var beginSpec = new BeginNewSpec(nodeTests.First().TypeName, nodeTests.First().MethodName, nodeTests);

            //register the TestActor as a subscriber for FactData announcements
            testRunCoordinator.Tell(new TestRunCoordinator.SubscribeFactCompletionMessages(TestActor));

            //begin a new spec
            testRunCoordinator.Tell(beginSpec);

            // create some messages for each node, the test runner, and some result messages
            // just like a real MultiNodeSpec
            var allMessages    = NodeMessageHelpers.GenerateMessageSequence(nodeIndexes, 300);
            var runnerMessages = NodeMessageHelpers.GenerateTestRunnerMessageSequence(20);
            var passMessages   = NodeMessageHelpers.GenerateResultMessage(nodeIndexes, true);

            allMessages.UnionWith(runnerMessages);
            allMessages.UnionWith(passMessages);

            foreach (var message in allMessages)
            {
                testRunCoordinator.Tell(message);
            }

            //end the spec
            testRunCoordinator.Tell(new EndSpec());

            var factData = ExpectMsg <FactData>();

            Assert.True(factData.Passed.Value, "Spec should have passed");
            Assert.True(factData.NodeFacts.All(x => x.Value.Passed.Value), "All individual nodes should have reported test pass");
        }