|
1 |
| -using System.Collections.Generic; |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using System.IO;
|
3 | 4 | using System.Linq;
|
4 | 5 |
|
5 | 6 | using Dynamo.Graph.Workspaces;
|
6 | 7 | using Dynamo.Models;
|
| 8 | +using Dynamo.Graph.Nodes; |
7 | 9 | using NUnit.Framework;
|
8 | 10 |
|
9 | 11 | namespace Dynamo.Tests
|
@@ -94,5 +96,58 @@ public void TestProfilingSingleNodePublicMethodsOnly()
|
94 | 96 | Assert.IsNotNull(profilingData.NodeExecutionTime(node));
|
95 | 97 | Assert.Greater(profilingData.NodeExecutionTime(node)?.Ticks, 0);
|
96 | 98 | }
|
| 99 | + |
| 100 | + private static List<Guid> executingNodes = new List<Guid>(); |
| 101 | + private static int nodeExecutionBeginCount = 0; |
| 102 | + private static int nodeExecutionEndCount = 0; |
| 103 | + |
| 104 | + private static void onNodeExectuionBegin(NodeModel model) |
| 105 | + { |
| 106 | + // Assert that the node has ot been executed more than once |
| 107 | + CollectionAssert.DoesNotContain(executingNodes, model.GUID); |
| 108 | + |
| 109 | + executingNodes.Add(model.GUID); |
| 110 | + nodeExecutionBeginCount++; |
| 111 | + } |
| 112 | + |
| 113 | + private static void onNodeExectuionEnd(NodeModel model) |
| 114 | + { |
| 115 | + // Assert that the node ending execution had the begin exectuion event fired previously |
| 116 | + CollectionAssert.Contains(executingNodes, model.GUID); |
| 117 | + |
| 118 | + nodeExecutionEndCount++; |
| 119 | + } |
| 120 | + |
| 121 | + [Test] |
| 122 | + public void TestNodeExecutionEvents() |
| 123 | + { |
| 124 | + // Note: This test file is saved in manual run mode |
| 125 | + string openPath = Path.Combine(TestDirectory, @"core\profiling\createSomePoints.dyn"); |
| 126 | + OpenModel(openPath); |
| 127 | + |
| 128 | + var nodes = CurrentDynamoModel.CurrentWorkspace.Nodes; |
| 129 | + foreach(var node in nodes) |
| 130 | + { |
| 131 | + node.NodeExecutionBegin += onNodeExectuionBegin; |
| 132 | + node.NodeExecutionEnd += onNodeExectuionEnd; |
| 133 | + } |
| 134 | + |
| 135 | + // Currently the node execution begin/end events are only enabled when profiling is enabled |
| 136 | + var engineController = CurrentDynamoModel.EngineController; |
| 137 | + var homeWorkspace = CurrentDynamoModel.Workspaces.OfType<HomeWorkspaceModel>().FirstOrDefault(); |
| 138 | + engineController.EnableProfiling(true, homeWorkspace, nodes); |
| 139 | + |
| 140 | + BeginRun(); |
| 141 | + |
| 142 | + // Assert that all nodes were executed and the begin and end events were fired as expectd |
| 143 | + Assert.AreEqual(4, nodeExecutionBeginCount); |
| 144 | + Assert.AreEqual(4, nodeExecutionEndCount); |
| 145 | + |
| 146 | + foreach (var node in nodes) |
| 147 | + { |
| 148 | + node.NodeExecutionBegin -= onNodeExectuionBegin; |
| 149 | + node.NodeExecutionEnd -= onNodeExectuionEnd; |
| 150 | + } |
| 151 | + } |
97 | 152 | }
|
98 | 153 | }
|
0 commit comments