-
Notifications
You must be signed in to change notification settings - Fork 938
Expand file tree
/
Copy pathProjectSpecificTests.cs
More file actions
154 lines (131 loc) · 5.62 KB
/
Copy pathProjectSpecificTests.cs
File metadata and controls
154 lines (131 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Aspire.Hosting;
using Aspire.Hosting.Tests.Utils;
using Aspire.Components.Common.Tests;
using SamplesIntegrationTests;
using SamplesIntegrationTests.Infrastructure;
using Xunit;
using Xunit.Abstractions;
namespace Aspire.Playground.Tests;
public class ProjectSpecificTests(ITestOutputHelper _testOutput)
{
[Fact]
public async Task WithDockerfileTest()
{
var appHostPath = Directory.GetFiles(AppContext.BaseDirectory, "WithDockerfile.AppHost.dll").Single();
var appHost = await DistributedApplicationTestFactory.CreateAsync(appHostPath, _testOutput);
await using var app = await appHost.BuildAsync();
await app.StartAsync();
await app.WaitForResources().WaitAsync(TimeSpan.FromMinutes(2));
await app.WaitForTextAsync($"I'm Batman. - Batman")
.WaitAsync(TimeSpan.FromMinutes(3));
app.EnsureNoErrorsLogged();
await app.StopAsync();
}
[Fact]
[ActiveIssue("https://github.com/dotnet/aspire/issues/6867")]
public async Task KafkaTest()
{
var appHostPath = Directory.GetFiles(AppContext.BaseDirectory, "KafkaBasic.AppHost.dll").Single();
var appHost = await DistributedApplicationTestFactory.CreateAsync(appHostPath, _testOutput);
await using var app = await appHost.BuildAsync();
await app.StartAsync();
await app.WaitForResources().WaitAsync(TimeSpan.FromMinutes(2));
// Wait for the producer to start sending messages
await app.WaitForTextAsync("Hello, World!").WaitAsync(TimeSpan.FromMinutes(5));
// Wait for the consumer to receive some messages
await WaitForAllTextAsync(app,
[
"Hello, World! 343",
"Received 1000 messages."
],
timeoutSecs: 120);
app.EnsureNoErrorsLogged();
await app.StopAsync();
}
[Fact]
[RequiresDocker]
[RequiresTools(["func"])]
public async Task AzureFunctionsTest()
{
var appHostPath = Directory.GetFiles(AppContext.BaseDirectory, "AzureFunctionsEndToEnd.AppHost.dll").Single();
var appHost = await DistributedApplicationTestFactory.CreateAsync(appHostPath, _testOutput);
await using var app = await appHost.BuildAsync();
await app.StartAsync();
await app.WaitForResources().WaitAsync(TimeSpan.FromMinutes(2));
// Wait for the 'Job host started' message as an indication
// that the Functions host has initialized correctly
await WaitForAllTextAsync(app,
[
"Worker process started and initialized."
],
resourceName: "funcapp",
timeoutSecs: 160);
// Assert that HTTP triggers work correctly
await AppHostTests.CreateHttpClientWithResilience(app, "funcapp").GetAsync("/api/injected-resources");
await WaitForAllTextAsync(app,
[
"Executed 'Functions.injected-resources'"
],
resourceName: "funcapp",
timeoutSecs: 160);
using var apiServiceClient = AppHostTests.CreateHttpClientWithResilience(app, "apiservice");
// Assert that Azure Storage Queue triggers work correctly
await apiServiceClient.GetAsync("/publish/asq");
await WaitForAllTextAsync(app,
[
"Executed 'Functions.MyAzureQueueTrigger'"
],
resourceName: "funcapp",
timeoutSecs: 160);
// Assert that Azure Storage Blob triggers work correctly
await apiServiceClient.GetAsync("/publish/blob");
await WaitForAllTextAsync(app,
[
"Executed 'Functions.MyAzureBlobTrigger'"
],
resourceName: "funcapp",
timeoutSecs: 160);
// Assert that EventHubs triggers work correctly
await apiServiceClient.GetAsync("/publish/eventhubs");
await WaitForAllTextAsync(app,
[
"Executed 'Functions.MyEventHubTrigger'"
],
resourceName: "funcapp",
timeoutSecs: 160);
#if !SKIP_UNSTABLE_EMULATORS // https://github.com/dotnet/aspire/issues/7066
// Assert that ServiceBus triggers work correctly
await apiServiceClient.GetAsync("/publish/asb");
await WaitForAllTextAsync(app,
[
"Executed 'Functions.MyServiceBusTrigger'"
],
resourceName: "funcapp",
timeoutSecs: 160);
#endif
// Assert that CosmosDB triggers work correctly
await apiServiceClient.GetAsync("/publish/cosmosdb");
await WaitForAllTextAsync(app,
[
"Executed 'Functions.MyCosmosDbTrigger'"
],
resourceName: "funcapp",
timeoutSecs: 160);
// TODO: The following line is commented out because the test fails due to an erroneous log in the Functions App
// resource that happens after the Functions host has been built. The error log shows up after the Functions
// worker extension has been built and before the host has launched.
// app.EnsureNoErrorsLogged();
await app.StopAsync();
}
internal static Task WaitForAllTextAsync(DistributedApplication app, IEnumerable<string> logTexts, string? resourceName = null, int timeoutSecs = -1)
{
CancellationTokenSource cts = new();
if (timeoutSecs > 0)
{
cts.CancelAfter(TimeSpan.FromSeconds(timeoutSecs));
}
return app.WaitForAllTextAsync(logTexts, resourceName, cts.Token);
}
}