1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
+ using System . Diagnostics ;
5
+
4
6
using Microsoft . Testing . Platform . Acceptance . IntegrationTests . Helpers ;
5
7
using Microsoft . Testing . Platform . Helpers ;
6
8
@@ -10,6 +12,8 @@ namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests;
10
12
public class ExecutionTests : AcceptanceTestBase
11
13
{
12
14
private const string AssetName = "ExecutionTests" ;
15
+ private const string AssetName2 = "ExecutionTests2" ;
16
+
13
17
private readonly TestAssetFixture _testAssetFixture ;
14
18
15
19
public ExecutionTests ( ITestExecutionContext testExecutionContext , TestAssetFixture testAssetFixture )
@@ -121,6 +125,17 @@ public async Task Exec_WhenListTestsAndMinimumExpectedTestsAreSpecified_Discover
121
125
Assert . That ( testHostResult . StandardOutput . Contains ( OutputPattern ) , $ "Output of the test host is:\n { testHostResult } ") ;
122
126
}
123
127
128
+ [ ArgumentsProvider ( nameof ( TargetFrameworks . All ) , typeof ( TargetFrameworks ) ) ]
129
+ public async Task Exec_Honor_Request_Complete ( string tfm )
130
+ {
131
+ TestInfrastructure . TestHost testHost = TestInfrastructure . TestHost . LocateFrom ( _testAssetFixture . TargetAssetPath2 , AssetName2 , tfm ) ;
132
+ Stopwatch stopwatch = Stopwatch . StartNew ( ) ;
133
+ TestHostResult testHostResult = await testHost . ExecuteAsync ( ) ;
134
+ stopwatch . Stop ( ) ;
135
+ Assert . AreEqual ( ExitCodes . Success , testHostResult . ExitCode ) ;
136
+ Assert . IsTrue ( stopwatch . Elapsed . TotalSeconds > 3 ) ;
137
+ }
138
+
124
139
[ TestFixture ( TestFixtureSharingStrategy . PerTestGroup ) ]
125
140
public sealed class TestAssetFixture ( AcceptanceFixture acceptanceFixture ) : TestAssetFixtureBase ( acceptanceFixture . NuGetGlobalPackagesFolder )
126
141
{
@@ -180,17 +195,98 @@ public void FilteredOutTest()
180
195
global using Microsoft.Testing.Platform.Builder;
181
196
global using Microsoft.Testing.Framework;
182
197
global using Microsoft.Testing.Extensions;
198
+ """ ;
199
+
200
+ private const string TestCode2 = """
201
+ #file ExecutionTests2.csproj
202
+ <Project Sdk="Microsoft.NET.Sdk">
203
+ <PropertyGroup>
204
+ <TargetFrameworks>$TargetFrameworks$</TargetFrameworks>
205
+ <ImplicitUsings>enable</ImplicitUsings>
206
+ <Nullable>enable</Nullable>
207
+ <OutputType>Exe</OutputType>
208
+ <UseAppHost>true</UseAppHost>
209
+ <LangVersion>preview</LangVersion>
210
+ </PropertyGroup>
211
+ <ItemGroup>
212
+ <PackageReference Include="Microsoft.Testing.Platform" Version="$MicrosoftTestingPlatformVersion$" />
213
+ </ItemGroup>
214
+ </Project>
215
+
216
+ #file Program.cs
217
+ using Microsoft.Testing.Platform;
218
+ using Microsoft.Testing.Platform.Extensions;
219
+ using Microsoft.Testing.Platform.Builder;
220
+ using Microsoft.Testing.Platform.Capabilities;
221
+ using Microsoft.Testing.Platform.Capabilities.TestFramework;
222
+ using Microsoft.Testing.Platform.Extensions.Messages;
223
+ using Microsoft.Testing.Platform.Extensions.TestFramework;
224
+ using System.Threading.Tasks;
225
+
226
+ ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args);
227
+ builder.RegisterTestFramework(_ => new Capabilities(), (_, __) => new DummyAdapter());
228
+ using ITestApplication app = await builder.BuildAsync();
229
+ return await app.RunAsync();
230
+
231
+ internal class DummyAdapter : ITestFramework, IDataProducer
232
+ {
233
+ public string Uid => nameof(DummyAdapter);
234
+
235
+ public string Version => string.Empty;
236
+
237
+ public string DisplayName => string.Empty;
238
+
239
+ public string Description => string.Empty;
240
+
241
+ public Type[] DataTypesProduced => new[] { typeof(TestNodeUpdateMessage) };
242
+
243
+ public Task<CloseTestSessionResult> CloseTestSessionAsync(CloseTestSessionContext context) => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true });
244
+
245
+ public Task<CreateTestSessionResult> CreateTestSessionAsync(CreateTestSessionContext context) => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true });
246
+
247
+ public Task ExecuteRequestAsync(ExecuteRequestContext context)
248
+ {
249
+ Task.Run(async() =>
250
+ {
251
+ await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(
252
+ context.Request.Session.SessionUid,
253
+ new TestNode() { Uid = "0", DisplayName = "Test", Properties = new(PassedTestNodeStateProperty.CachedInstance) }));
254
+
255
+ Thread.Sleep(3_000);
256
+
257
+ context.Complete();
258
+ });
259
+
260
+ return Task.CompletedTask;
261
+ }
262
+
263
+ public Task<bool> IsEnabledAsync() => Task.FromResult(true);
264
+ }
265
+
266
+ internal class Capabilities : ITestFrameworkCapabilities
267
+ {
268
+ IReadOnlyCollection<ITestFrameworkCapability> ICapabilities<ITestFrameworkCapability>.Capabilities => Array.Empty<ITestFrameworkCapability>();
269
+ }
270
+
183
271
""" ;
184
272
185
273
public string TargetAssetPath => GetAssetPath ( AssetName ) ;
186
274
275
+ public string TargetAssetPath2 => GetAssetPath ( AssetName2 ) ;
276
+
187
277
public override IEnumerable < ( string ID , string Name , string Code ) > GetAssetsToGenerate ( )
188
278
{
189
279
yield return ( AssetName , AssetName ,
190
280
TestCode
191
281
. PatchTargetFrameworks ( TargetFrameworks . All )
192
282
. PatchCodeWithReplace ( "$MicrosoftTestingPlatformVersion$" , MicrosoftTestingPlatformVersion )
193
283
. PatchCodeWithReplace ( "$MicrosoftTestingPlatformExtensionsVersion$" , MicrosoftTestingPlatformExtensionsVersion ) ) ;
284
+
285
+ yield return ( AssetName2 , AssetName2 ,
286
+ TestCode2
287
+ . PatchTargetFrameworks ( TargetFrameworks . All )
288
+ . PatchCodeWithReplace ( "$MicrosoftTestingPlatformVersion$" , MicrosoftTestingPlatformVersion )
289
+ . PatchCodeWithReplace ( "$MicrosoftTestingPlatformExtensionsVersion$" , MicrosoftTestingPlatformExtensionsVersion ) ) ;
194
290
}
195
291
}
196
292
}
0 commit comments