Skip to content

Commit e9acf4f

Browse files
committed
Merge pull request #44 from Microsoft/users/ersciple/m98fixunittest
Fix unit test.
2 parents 08a7638 + 51d6a66 commit e9acf4f

File tree

2 files changed

+60
-59
lines changed

2 files changed

+60
-59
lines changed

src/Test/L0/Listener/JobDispatcherL0.cs

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -83,62 +83,63 @@ public async void DispatchesJobRequest()
8383
}
8484
}
8585

86-
[Fact(Skip = "Need Refect JobDispatcher.")]
87-
[Trait("Level", "L0")]
88-
[Trait("Category", "Agent")]
89-
public async void DispatchesCancellationRequest()
90-
{
91-
//Arrange
92-
using (var hc = new TestHostContext(this))
93-
using (var jobDispatcher = new JobDispatcher())
94-
{
95-
hc.SetSingleton<IConfigurationStore>(_configurationStore.Object);
96-
hc.SetSingleton<IAgentServer>(_agentServer.Object);
97-
98-
hc.EnqueueInstance<IProcessChannel>(_processChannel.Object);
99-
hc.EnqueueInstance<IProcessInvoker>(_processInvoker.Object);
100-
jobDispatcher.Initialize(hc);
101-
var ts = new CancellationTokenSource();
102-
CancellationToken token = ts.Token;
103-
JobRequestMessage message = CreateJobRequestMessage();
104-
string strMessage = JsonUtility.ToString(message);
105-
106-
_processInvoker.Setup(x => x.ExecuteAsync(It.IsAny<String>(), It.IsAny<String>(), "spawnclient 1 2", null, It.IsAny<CancellationToken>()))
107-
.Returns(async(String workingFolder, String filename, String arguments, IDictionary<String, String> environment, CancellationToken cancellationToken) =>
108-
{
109-
await Task.Delay(5000);
110-
return 1;
111-
});
112-
113-
_processChannel.Setup(x => x.StartServer(It.IsAny<StartProcessDelegate>()))
114-
.Callback((StartProcessDelegate startDel) => { startDel("1", "2"); });
115-
_processChannel.Setup(x => x.SendAsync(MessageType.NewJobRequest, It.Is<string>(s => s.Equals(strMessage)), It.IsAny<CancellationToken>()))
116-
.Returns(Task.CompletedTask);
117-
_processChannel.Setup(x => x.SendAsync(MessageType.CancelRequest, It.IsAny<String>(), It.IsAny<CancellationToken>()))
118-
.Returns(Task.CompletedTask);
119-
120-
_configurationStore.Setup(x => x.GetSettings()).Returns(new AgentSettings() { PoolId = 1 });
121-
122-
var request = new TaskAgentJobRequest();
123-
PropertyInfo sessionIdProperty = request.GetType().GetProperty("LockedUntil", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
124-
Assert.NotNull(sessionIdProperty);
125-
sessionIdProperty.SetValue(request, DateTime.UtcNow.AddMinutes(5));
126-
127-
_agentServer.Setup(x => x.RenewAgentRequestAsync(It.IsAny<int>(), It.IsAny<long>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>())).Returns(Task.FromResult<TaskAgentJobRequest>(request));
128-
129-
_agentServer.Setup(x => x.FinishAgentRequestAsync(It.IsAny<int>(), It.IsAny<long>(), It.IsAny<Guid>(), It.IsAny<DateTime>(), It.IsAny<TaskResult>(), It.IsAny<CancellationToken>())).Returns(Task.FromResult<TaskAgentJobRequest>(new TaskAgentJobRequest()));
130-
131-
132-
//Act
133-
Task<int> runAsyncTask = jobDispatcher.RunAsync(message, ts.Token);
134-
ts.Cancel();
135-
await runAsyncTask;
86+
// TODO: Fix after JobDispatcher changes.
87+
// [Fact]
88+
// [Trait("Level", "L0")]
89+
// [Trait("Category", "Agent")]
90+
// public async void DispatchesCancellationRequest()
91+
// {
92+
// //Arrange
93+
// using (var hc = new TestHostContext(this))
94+
// using (var jobDispatcher = new JobDispatcher())
95+
// {
96+
// hc.SetSingleton<IConfigurationStore>(_configurationStore.Object);
97+
// hc.SetSingleton<IAgentServer>(_agentServer.Object);
98+
99+
// hc.EnqueueInstance<IProcessChannel>(_processChannel.Object);
100+
// hc.EnqueueInstance<IProcessInvoker>(_processInvoker.Object);
101+
// jobDispatcher.Initialize(hc);
102+
// var ts = new CancellationTokenSource();
103+
// CancellationToken token = ts.Token;
104+
// JobRequestMessage message = CreateJobRequestMessage();
105+
// string strMessage = JsonUtility.ToString(message);
106+
107+
// _processInvoker.Setup(x => x.ExecuteAsync(It.IsAny<String>(), It.IsAny<String>(), "spawnclient 1 2", null, It.IsAny<CancellationToken>()))
108+
// .Returns(async(String workingFolder, String filename, String arguments, IDictionary<String, String> environment, CancellationToken cancellationToken) =>
109+
// {
110+
// await Task.Delay(5000);
111+
// return 1;
112+
// });
113+
114+
// _processChannel.Setup(x => x.StartServer(It.IsAny<StartProcessDelegate>()))
115+
// .Callback((StartProcessDelegate startDel) => { startDel("1", "2"); });
116+
// _processChannel.Setup(x => x.SendAsync(MessageType.NewJobRequest, It.Is<string>(s => s.Equals(strMessage)), It.IsAny<CancellationToken>()))
117+
// .Returns(Task.CompletedTask);
118+
// _processChannel.Setup(x => x.SendAsync(MessageType.CancelRequest, It.IsAny<String>(), It.IsAny<CancellationToken>()))
119+
// .Returns(Task.CompletedTask);
120+
121+
// _configurationStore.Setup(x => x.GetSettings()).Returns(new AgentSettings() { PoolId = 1 });
122+
123+
// var request = new TaskAgentJobRequest();
124+
// PropertyInfo sessionIdProperty = request.GetType().GetProperty("LockedUntil", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
125+
// Assert.NotNull(sessionIdProperty);
126+
// sessionIdProperty.SetValue(request, DateTime.UtcNow.AddMinutes(5));
127+
128+
// _agentServer.Setup(x => x.RenewAgentRequestAsync(It.IsAny<int>(), It.IsAny<long>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>())).Returns(Task.FromResult<TaskAgentJobRequest>(request));
129+
130+
// _agentServer.Setup(x => x.FinishAgentRequestAsync(It.IsAny<int>(), It.IsAny<long>(), It.IsAny<Guid>(), It.IsAny<DateTime>(), It.IsAny<TaskResult>(), It.IsAny<CancellationToken>())).Returns(Task.FromResult<TaskAgentJobRequest>(new TaskAgentJobRequest()));
131+
132+
133+
// //Act
134+
// Task<int> runAsyncTask = jobDispatcher.RunAsync(message, ts.Token);
135+
// ts.Cancel();
136+
// await runAsyncTask;
136137

137-
//Assert
138-
// Verify the cancellation message was sent
139-
_processChannel.Verify(x => x.SendAsync(MessageType.CancelRequest, It.IsAny<String>(), It.IsAny<CancellationToken>()),
140-
"Cancelation message not sent");
141-
}
142-
}
138+
// //Assert
139+
// // Verify the cancellation message was sent
140+
// _processChannel.Verify(x => x.SendAsync(MessageType.CancelRequest, It.IsAny<String>(), It.IsAny<CancellationToken>()),
141+
// "Cancelation message not sent");
142+
// }
143+
// }
143144
}
144145
}

src/Test/L0/Worker/VariablesL0.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void Constructor_InheritsSecretFlagFromDeepRecursion()
178178
var copy = new Dictionary<string, string>
179179
{
180180
{ "variable1", "before $(variable2) after" },
181-
{ "variable2", "before2 ($variable3) after2" },
181+
{ "variable2", "before2 $(variable3) after2" },
182182
{ "variable3", "some variable 3 value" },
183183
};
184184
var maskHints = new List<MaskHint>
@@ -193,8 +193,8 @@ public void Constructor_InheritsSecretFlagFromDeepRecursion()
193193
// Assert.
194194
Assert.Equal(0, warnings.Count);
195195
Assert.Equal(0, variables.Public.Count());
196-
Assert.Equal("before2 before some variable 3 value after after2", variables.Get("variable1"));
197-
Assert.Equal("before2 some variable 2 value after2", variables.Get("variable2"));
196+
Assert.Equal("before before2 some variable 3 value after2 after", variables.Get("variable1"));
197+
Assert.Equal("before2 some variable 3 value after2", variables.Get("variable2"));
198198
Assert.Equal("some variable 3 value", variables.Get("variable3"));
199199
}
200200
}

0 commit comments

Comments
 (0)