Skip to content

Commit c707a03

Browse files
committed
removing test filter; fixing issues in failing tests
1 parent 0e20297 commit c707a03

File tree

6 files changed

+58
-38
lines changed

6 files changed

+58
-38
lines changed

appveyor.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ test_script:
4040
4141
$success = $success -and $?
4242
43-
dotnet test .\test\WebJobs.Script.Tests.Integration\ -v q --no-build --filter "(FullyQualifiedName~Tests.NodeEndToEndTests|FullyQualifiedName~NodeContentTests|FullyQualifiedName~Tests.SecretsRepositoryTests|FullyQualifiedName~StandbyModeTests)"
44-
43+
dotnet test .\test\WebJobs.Script.Tests.Integration\ -v q --no-build
44+
4545
$success = $success -and $?
4646
47-
# Skipping integration tests for initial build # dotnet test .\test\WebJobs.Script.Tests.Integration\ -v q --no-build
48-
4947
if (-not $success) { exit 1 }

test/WebJobs.Script.Tests.Integration/ApplicationInsights/ApplicationInsightsEndToEndTestsBase.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ public async Task Validate_HostLogs()
217217
// slightly out-of-order or on different threads
218218
TraceTelemetry[] traces = null;
219219

220+
int expectedCount = 11;
221+
220222
await TestHelpers.Await(() =>
221223
{
222224
traces = _fixture.Channel.Telemetries
@@ -225,22 +227,25 @@ await TestHelpers.Await(() =>
225227
.OrderBy(t => t.Message)
226228
.ToArray();
227229

228-
return traces.Length >= 9;
230+
// When these two messages are logged, we know we've completed initialization.
231+
return traces
232+
.Where(t => t.Message.Contains("Host lock lease acquired by instance ID") || t.Message.Contains("Job host started"))
233+
.Count() == 2;
229234
});
230235

231-
Assert.True(traces.Length == 9, $"Expected 9 messages, but found {traces.Length}. Actual logs:{Environment.NewLine}{string.Join(Environment.NewLine, traces.Select(t => t.Message))}");
236+
Assert.True(traces.Length == expectedCount, $"Expected {expectedCount} messages, but found {traces.Length}. Actual logs:{Environment.NewLine}{string.Join(Environment.NewLine, traces.Select(t => t.Message))}");
232237

233238
ValidateTrace(traces[0], "A function whitelist has been specified", LogCategories.Startup);
234239
ValidateTrace(traces[1], "Found the following functions:\r\n", LogCategories.Startup);
235240
ValidateTrace(traces[2], "Generating 2 job function(s)", LogCategories.Startup);
236241
ValidateTrace(traces[3], "Host configuration file read:", LogCategories.Startup);
237242
ValidateTrace(traces[4], "Host id explicitly set", LogCategories.Startup, expectedLevel: SeverityLevel.Warning);
238-
ValidateTrace(traces[5], "Host lock lease acquired by instance ID", ScriptConstants.LogCategoryHostGeneral);
239-
ValidateTrace(traces[6], "Job host started", LogCategories.Startup);
240-
ValidateTrace(traces[7], "Reading host configuration file", LogCategories.Startup);
241-
ValidateTrace(traces[8], "Starting Host (HostId=function-tests-", ScriptConstants.LogCategoryHostGeneral);
242-
243-
await Task.CompletedTask;
243+
ValidateTrace(traces[5], "Host initialized (", LogCategories.Startup);
244+
ValidateTrace(traces[6], "Host lock lease acquired by instance ID", ScriptConstants.LogCategoryHostGeneral);
245+
ValidateTrace(traces[7], "Host started (", LogCategories.Startup);
246+
ValidateTrace(traces[8], "Job host started", LogCategories.Startup);
247+
ValidateTrace(traces[9], "Reading host configuration file", LogCategories.Startup);
248+
ValidateTrace(traces[10], "Starting Host (HostId=function-tests-", ScriptConstants.LogCategoryHostGeneral);
244249
}
245250

246251
private static void ValidateMetric(MetricTelemetry telemetry, string expectedOperationId, string expectedOperationName)

test/WebJobs.Script.Tests.Integration/ApplicationInsights/ApplicationInsightsTestFixture.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Collections.Generic;
56
using System.IO;
67
using System.Net.Http;
78
using Microsoft.AspNetCore.Hosting;
89
using Microsoft.AspNetCore.TestHost;
910
using Microsoft.Azure.WebJobs.Script.Config;
1011
using Microsoft.Azure.WebJobs.Script.WebHost;
12+
using Microsoft.Extensions.Configuration;
1113
using Microsoft.Extensions.DependencyInjection;
1214
using Microsoft.Extensions.DependencyInjection.Extensions;
1315
using Microsoft.WebJobs.Script.Tests;
@@ -33,7 +35,19 @@ public ApplicationInsightsTestFixture(string scriptRoot, string testId)
3335
.UseStartup<Startup>()
3436
.ConfigureServices(services =>
3537
{
36-
ScriptSettingsManager.Instance.ApplicationInsightsInstrumentationKey = TestChannelLoggerProviderFactory.ApplicationInsightsKey;
38+
var settingsManager = new ScriptSettingsManager();
39+
settingsManager.SetConfigurationFactory(() =>
40+
{
41+
return new ConfigurationBuilder()
42+
.AddInMemoryCollection(new Dictionary<string, string>
43+
{
44+
[EnvironmentSettingNames.AppInsightsInstrumentationKey] = TestChannelLoggerProviderFactory.ApplicationInsightsKey
45+
})
46+
.AddEnvironmentVariables()
47+
.Build();
48+
});
49+
50+
services.Replace(new ServiceDescriptor(typeof(ScriptSettingsManager), settingsManager));
3751
services.Replace(new ServiceDescriptor(typeof(WebHostSettings), HostSettings));
3852
services.Replace(new ServiceDescriptor(typeof(ILoggerProviderFactory), new TestChannelLoggerProviderFactory(Channel)));
3953
services.Replace(new ServiceDescriptor(typeof(ISecretManager), new TestSecretManager()));
@@ -76,6 +90,7 @@ public void Dispose()
7690
{
7791
_testServer?.Dispose();
7892
HttpClient?.Dispose();
93+
ScriptSettingsManager.Instance.Reset();
7994
}
8095
}
8196
}

test/WebJobs.Script.Tests.Integration/Controllers/ControllerScenarioTestFixture.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@
44
using System.IO;
55
using System.Net.Http;
66
using System.Web.Http;
7-
using Autofac;
87
using Microsoft.AspNetCore.Hosting;
98
using Microsoft.AspNetCore.TestHost;
109
using Microsoft.Azure.WebJobs.Script.Config;
11-
using Microsoft.Azure.WebJobs.Script.Tests.Integration;
1210
using Microsoft.Azure.WebJobs.Script.WebHost;
13-
using Microsoft.Extensions.DependencyInjection;
14-
using Microsoft.Extensions.Logging;
1511
using Microsoft.Extensions.Configuration;
16-
using Microsoft.Extensions.Logging.Console;
12+
using Microsoft.Extensions.DependencyInjection;
1713

1814
namespace Microsoft.Azure.WebJobs.Script.Tests.Controllers
1915
{
@@ -28,7 +24,7 @@ public ControllerScenarioTestFixture()
2824
}
2925

3026
public ControllerScenarioTestFixture(bool isAuthDisabled)
31-
{
27+
{
3228
_config = new HttpConfiguration();
3329
_settingsManager = ScriptSettingsManager.Instance;
3430

test/WebJobs.Script.Tests.Integration/Host/ScriptHostManagerTests.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ string GetErrorTraces()
7171
userMessageCallback: GetErrorTraces).GetAwaiter().GetResult();
7272

7373
// Wait for initial execution.
74-
TestHelpers.Await(() =>
74+
TestHelpers.Await(async () =>
7575
{
76-
bool exists = blob1.ExistsAsync().GetAwaiter().GetResult();
76+
bool exists = await blob1.ExistsAsync();
7777
return exists;
7878
}, timeout: 10 * 1000, userMessageCallback: GetErrorTraces).GetAwaiter().GetResult();
7979

8080
// This changes the bindings so that we now write to blob2
8181
var blob2 = UpdateOutputName("first", "testblob", fixture).Result;
8282

8383
// wait for newly executed
84-
TestHelpers.Await(() =>
84+
TestHelpers.Await(async () =>
8585
{
86-
bool exists = blob2.ExistsAsync().GetAwaiter().GetResult();
86+
bool exists = await blob2.ExistsAsync();
8787
return exists;
8888
}, timeout: 30 * 1000, userMessageCallback: GetErrorTraces).GetAwaiter().GetResult();
8989

@@ -128,7 +128,7 @@ string GetErrorTraces()
128128
}
129129

130130
[Fact]
131-
public void RenameFunctionAndRestart()
131+
public async Task RenameFunctionAndRestart()
132132
{
133133
var oldDirectory = Path.Combine(Directory.GetCurrentDirectory(), "TestScripts/Node/TimerTrigger");
134134
var newDirectory = Path.Combine(Directory.GetCurrentDirectory(), "TestScripts/Node/MovedTrigger");
@@ -142,6 +142,7 @@ public void RenameFunctionAndRestart()
142142
};
143143

144144
var blob = fixture.TestOutputContainer.GetBlockBlobReference("testblob");
145+
await blob.DeleteIfExistsAsync();
145146
var mockEnvironment = new Mock<IScriptHostEnvironment>();
146147

147148
using (var eventManager = new ScriptEventManager())
@@ -167,12 +168,12 @@ public void RenameFunctionAndRestart()
167168
userMessageCallback: () => "Host did not start in time.").GetAwaiter().GetResult();
168169

169170
// Wait for initial execution.
170-
TestHelpers.Await(() =>
171-
{
172-
bool exists = blob.ExistsAsync().GetAwaiter().GetResult();
173-
return exists;
174-
}, timeout: 10 * 1000,
175-
userMessageCallback: () => $"Blob '{blob.Uri}' was not created by 'TimerTrigger' in time.").GetAwaiter().GetResult();
171+
TestHelpers.Await(async () =>
172+
{
173+
bool exists = await blob.ExistsAsync();
174+
return exists;
175+
}, timeout: 10 * 1000,
176+
userMessageCallback: () => $"Blob '{blob.Uri}' was not created by 'TimerTrigger' in time.").GetAwaiter().GetResult();
176177

177178
// find __dirname from blob
178179
string text;
@@ -189,15 +190,15 @@ public void RenameFunctionAndRestart()
189190

190191
resetEvent.Wait(TimeSpan.FromSeconds(10));
191192

192-
blob.DeleteIfExistsAsync();
193+
blob.DeleteIfExistsAsync().GetAwaiter().GetResult();
193194

194195
// wait for newly executed
195-
TestHelpers.Await(() =>
196-
{
197-
bool exists = blob.ExistsAsync().GetAwaiter().GetResult();
198-
return exists;
199-
}, timeout: 30 * 1000,
200-
userMessageCallback: () => $"Blob '{blob.Uri}' was not created by 'MovedTrigger' in time.").GetAwaiter().GetResult();
196+
TestHelpers.Await(async () =>
197+
{
198+
bool exists = await blob.ExistsAsync();
199+
return exists;
200+
}, timeout: 30 * 1000,
201+
userMessageCallback: () => $"Blob '{blob.Uri}' was not created by 'MovedTrigger' in time.").GetAwaiter().GetResult();
201202

202203
using (var stream = new MemoryStream())
203204
{

test/WebJobs.Script.Tests.Integration/Host/StandbyManagerTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace Microsoft.Azure.WebJobs.Script.Tests
2222
{
23-
public class StandbyManagerTests
23+
public class StandbyManagerTests : IDisposable
2424
{
2525
private readonly ScriptSettingsManager _settingsManager;
2626

@@ -154,5 +154,10 @@ await TestHelpers.Await(() =>
154154
WebScriptHostManager.ResetStandbyMode();
155155
}
156156
}
157+
158+
public void Dispose()
159+
{
160+
ScriptSettingsManager.Instance.Reset();
161+
}
157162
}
158163
}

0 commit comments

Comments
 (0)