@@ -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}
0 commit comments