diff --git a/src/Runner.Worker/ExecutionContext.cs b/src/Runner.Worker/ExecutionContext.cs index a79f2b66d3e..cda70767ec6 100644 --- a/src/Runner.Worker/ExecutionContext.cs +++ b/src/Runner.Worker/ExecutionContext.cs @@ -136,6 +136,8 @@ public sealed class ExecutionContext : RunnerService, IExecutionContext private Guid _detailTimelineId; private bool _expandedForPostJob = false; private int _childTimelineRecordOrder = 0; + private int _childPostActionCounter = 0; + private CancellationTokenSource _cancellationTokenSource; private TaskCompletionSource _forceCompleted = new TaskCompletionSource(); private bool _throttlingReported = false; @@ -1043,7 +1045,7 @@ private IExecutionContext CreatePostChild(string displayName, Dictionary(), new List(), new Pipelines.JobResources(), new Pipelines.ContextData.DictionaryContextData(), new Pipelines.WorkspaceOptions(), new List(), null, null, null, null); + jobRequest.Resources.Repositories.Add(new Pipelines.RepositoryResource() + { + Alias = Pipelines.PipelineConstants.SelfAlias, + Id = "github", + Version = "sha1" + }); + jobRequest.ContextData["github"] = new Pipelines.ContextData.DictionaryContextData(); + jobRequest.Variables["ACTIONS_STEP_DEBUG"] = "true"; + + // Arrange: Setup the paging logger. + var pagingLogger1 = new Mock(); + var pagingLogger2 = new Mock(); + var pagingLogger3 = new Mock(); + var pagingLogger4 = new Mock(); + var pagingLogger5 = new Mock(); + var jobServerQueue = new Mock(); + + Dictionary timelineOutput = new Dictionary(); + + jobServerQueue.Setup(x => x.QueueTimelineRecordUpdate(It.IsAny(), It.IsAny())).Callback((Guid id, TimelineRecord timelineRecord) => + { + timelineOutput[timelineRecord.Name] = timelineRecord.Order; + }); + jobServerQueue.Setup(x => x.QueueWebConsoleLine(It.IsAny(), It.IsAny(), It.IsAny())); + + var actionRunner1 = new ActionRunner(); + actionRunner1.Initialize(hc); + var actionRunner2 = new ActionRunner(); + actionRunner2.Initialize(hc); + + hc.EnqueueInstance(pagingLogger1.Object); + hc.EnqueueInstance(pagingLogger2.Object); + hc.EnqueueInstance(pagingLogger3.Object); + hc.EnqueueInstance(pagingLogger4.Object); + hc.EnqueueInstance(pagingLogger5.Object); + hc.EnqueueInstance(actionRunner1 as IActionRunner); + hc.EnqueueInstance(actionRunner2 as IActionRunner); + hc.SetSingleton(jobServerQueue.Object); + + var jobContext = new Runner.Worker.ExecutionContext(); + jobContext.Initialize(hc); + + // Act. + jobContext.InitializeJob(jobRequest, CancellationToken.None); + + var action1 = jobContext.CreateChild(Guid.NewGuid(), "action_1", "action_1", null, null, 0); + var action2 = jobContext.CreateChild(Guid.NewGuid(), "action_2", "action_2", null, null, 0); + + var postRunner1 = hc.CreateService(); + postRunner1.Action = new Pipelines.ActionStep() { Id = Guid.NewGuid(), Name = "post1", DisplayName = "action_1_post", Reference = new Pipelines.RepositoryPathReference() { Name = "actions/action" } }; + postRunner1.Stage = ActionRunStage.Post; + postRunner1.Condition = "always()"; + postRunner1.DisplayName = "post1"; + + + var postRunner2 = hc.CreateService(); + postRunner2.Action = new Pipelines.ActionStep() { Id = Guid.NewGuid(), Name = "post2", DisplayName = "action_2_post", Reference = new Pipelines.RepositoryPathReference() { Name = "actions/action" } }; + postRunner2.Stage = ActionRunStage.Post; + postRunner2.Condition = "always()"; + postRunner2.DisplayName = "post2"; + + action1.RegisterPostJobStep(postRunner1); + action2.RegisterPostJobStep(postRunner2); + + + List> outputList = timelineOutput.ToList(); + outputList.Sort( + delegate (KeyValuePair kv1, KeyValuePair kv2) + { + // If step, order should be set + if (!kv1.Key.Equals(jobName)) { + Assert.NotNull(kv1.Value); + } + if (!kv2.Key.Equals(jobName)) { + Assert.NotNull(kv2.Value); + } + + int v1 = kv1.Value ?? default(int); + int v2 = kv2.Value ?? default(int); + return v1.CompareTo(v2); + } + ); + string[] expectedOutputNames = {jobName, "action_1", "action_2", "action_2_post", "action_1_post"}; + + int i = 0; + foreach(KeyValuePair kv in outputList) { + Assert.Equal(kv.Key, expectedOutputNames[i++]); + } + } + } + [Fact] [Trait("Level", "L0")] [Trait("Category", "Worker")]