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

Fixed Post Steps order timeline #1697

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Runner.Worker/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> _forceCompleted = new TaskCompletionSource<int>();
private bool _throttlingReported = false;
Expand Down Expand Up @@ -1043,7 +1045,7 @@ private IExecutionContext CreatePostChild(string displayName, Dictionary<string,
}

var newGuid = Guid.NewGuid();
return CreateChild(newGuid, displayName, newGuid.ToString("N"), null, null, ActionRunStage.Post, intraActionState, _childTimelineRecordOrder - Root.PostJobSteps.Count, siblingScopeName: siblingScopeName);
Copy link
Member

Choose a reason for hiding this comment

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

add some L0 tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

thboop marked this conversation as resolved.
Show resolved Hide resolved
return CreateChild(newGuid, displayName, newGuid.ToString("N"), null, null, ActionRunStage.Post, intraActionState, _childTimelineRecordOrder - (_childPostActionCounter++), siblingScopeName: siblingScopeName);
}
}

Expand Down
105 changes: 105 additions & 0 deletions src/Test/L0/Worker/ExecutionContextL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,111 @@ public void RegisterPostJobAction_NotRegisterPostTwice()
}
}

[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Worker")]
public void CreatePostChild_TimelineCheck()
{

using (TestHostContext hc = CreateTestContext())
{
// Arrange: Create a job request message.
TaskOrchestrationPlanReference plan = new TaskOrchestrationPlanReference();
TimelineReference timeline = new TimelineReference();
Guid jobId = Guid.NewGuid();
string jobName = "some job name";
var jobRequest = new Pipelines.AgentJobRequestMessage(plan, timeline, jobId, jobName, jobName, null, null, null, new Dictionary<string, VariableValue>(), new List<MaskHint>(), new Pipelines.JobResources(), new Pipelines.ContextData.DictionaryContextData(), new Pipelines.WorkspaceOptions(), new List<Pipelines.ActionStep>(), 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<IPagingLogger>();
var pagingLogger2 = new Mock<IPagingLogger>();
var pagingLogger3 = new Mock<IPagingLogger>();
var pagingLogger4 = new Mock<IPagingLogger>();
var pagingLogger5 = new Mock<IPagingLogger>();
var jobServerQueue = new Mock<IJobServerQueue>();

Dictionary<string, int?> timelineOutput = new Dictionary<string, int?>();

jobServerQueue.Setup(x => x.QueueTimelineRecordUpdate(It.IsAny<Guid>(), It.IsAny<TimelineRecord>())).Callback((Guid id, TimelineRecord timelineRecord) =>
{
timelineOutput[timelineRecord.Name] = timelineRecord.Order;
});
jobServerQueue.Setup(x => x.QueueWebConsoleLine(It.IsAny<Guid>(), It.IsAny<string>(), It.IsAny<long?>()));

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<IActionRunner>();
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<IActionRunner>();
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<KeyValuePair<string, int?>> outputList = timelineOutput.ToList();
outputList.Sort(
delegate (KeyValuePair<string, int?> kv1, KeyValuePair<string, int?> 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<string, int?> kv in outputList) {
Assert.Equal(kv.Key, expectedOutputNames[i++]);
}
}
}

[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Worker")]
Expand Down