Skip to content

Commit 6ee66db

Browse files
committed
making UpdateFileAndRestart test more resilient
1 parent 6eba74b commit 6ee66db

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

test/WebJobs.Script.Tests/ScriptHostManagerTests.cs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,59 @@
1515
namespace Microsoft.Azure.WebJobs.Script.Tests
1616
{
1717
[Trait("Category", "E2E")]
18-
public class ScriptHostManagerTests
18+
public class ScriptHostManagerTests
1919
{
2020
// Update a script file (the function.json) to force the ScriptHost to re-index and pick up new changes.
2121
// Test with timers:
2222
[Fact]
2323
public async Task UpdateFileAndRestart()
2424
{
25-
Random r = new Random();
26-
2725
CancellationTokenSource cts = new CancellationTokenSource();
2826

2927
var fixture = new NodeEndToEndTests.TestFixture();
3028
var blob1 = UpdateOutputName("testblob", "first", fixture);
3129

3230
await fixture.Host.StopAsync();
33-
var config = fixture.Host.ScriptConfig;
31+
var config = fixture.Host.ScriptConfig;
32+
33+
var success = true;
3434

3535
using (var manager = new ScriptHostManager(config))
3636
{
3737
// Background task to run while the main thread is pumping events at RunAndBlock().
3838
Thread t = new Thread(_ =>
3939
{
40-
// Wait for initial execution.
41-
TestHelpers.Await(() =>
40+
try
4241
{
43-
return blob1.Exists();
44-
}, timeout: 10 * 1000).Wait();
45-
46-
// This changes the bindings so that we now write to blob2
47-
var blob2 = UpdateOutputName("first", "second", fixture);
48-
49-
// wait for newly executed
50-
TestHelpers.Await(() =>
42+
// Wait for initial execution.
43+
TestHelpers.Await(() =>
44+
{
45+
return blob1.Exists();
46+
}, timeout: 10 * 1000).Wait();
47+
48+
// This changes the bindings so that we now write to blob2
49+
var blob2 = UpdateOutputName("first", "second", fixture);
50+
51+
// wait for newly executed
52+
TestHelpers.Await(() =>
53+
{
54+
return blob2.Exists();
55+
}, timeout: 30 * 1000).Wait();
56+
}
57+
catch
5158
{
52-
return blob2.Exists();
53-
}, timeout: 10 * 1000).Wait();
59+
success = false;
60+
}
5461

55-
manager.Stop();
62+
cts.Cancel();
5663
});
57-
t.Start();
64+
t.Start();
5865

5966
manager.RunAndBlock(cts.Token);
6067

6168
t.Join();
69+
70+
Assert.True(success);
6271
}
6372
}
6473

@@ -175,7 +184,7 @@ private static CloudBlockBlob UpdateOutputName(string prev, string hint, EndToEn
175184
string name = hint;
176185

177186
string manifestPath = Path.Combine(Environment.CurrentDirectory, @"TestScripts\Node\TimerTrigger\function.json");
178-
string content = File.ReadAllText(manifestPath);
187+
string content = File.ReadAllText(manifestPath);
179188
content = content.Replace(prev, name);
180189
File.WriteAllText(manifestPath, content);
181190

0 commit comments

Comments
 (0)