Skip to content

Commit d331f2b

Browse files
committed
Add never restart test
1 parent 8982e83 commit d331f2b

File tree

2 files changed

+57
-19
lines changed

2 files changed

+57
-19
lines changed

ExtractorUtils.Test/unit/Unstable/RuntimeTest.cs

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,8 @@ private ExtractorRuntimeBuilder<DummyConfig, DummyExtractor> CreateMockRuntimeBu
186186
return builder;
187187
}
188188

189-
[Fact(Timeout = 5000)]
190-
public async Task TestRuntimeRestartNewConfig()
189+
private async Task<(DummyExtractor, ExtractorRuntime<DummyConfig, DummyExtractor>)> createExtractorForRestartTest(ManualResetEventSlim evt, ExtractorRuntimeBuilder<DummyConfig, DummyExtractor> builder, CancellationToken token)
191190
{
192-
var builder = CreateMockRuntimeBuilder();
193-
// Restart policy won't be the default "Always" in customer envs, but we should
194-
// still restart on config change.
195-
builder.RestartPolicy = ExtractorRestartPolicy.OnError;
196-
197-
using var evt = new ManualResetEventSlim(false);
198-
199191
DummyExtractor extractor = null;
200192
builder.OnCreateExtractor = (_, ext) =>
201193
{
@@ -206,15 +198,27 @@ public async Task TestRuntimeRestartNewConfig()
206198
};
207199
};
208200

209-
using var source = new CancellationTokenSource();
210-
211-
var runtime = await builder.MakeRuntime(source.Token);
201+
var runtime = await builder.MakeRuntime(token);
212202
var runTask = runtime.Run();
213203

214-
Assert.True(await CommonUtils.WaitAsync(evt.WaitHandle, TimeSpan.FromSeconds(5), source.Token));
204+
Assert.True(await CommonUtils.WaitAsync(evt.WaitHandle, TimeSpan.FromSeconds(5), token));
215205
Assert.NotNull(extractor);
206+
return (extractor, runtime);
207+
}
208+
209+
[Fact(Timeout = 5000)]
210+
public async Task TestRuntimeRestartNewConfig()
211+
{
212+
var builder = CreateMockRuntimeBuilder();
213+
// Restart policy won't be the default "Always" in customer envs, but we should
214+
// still restart on config change.
215+
builder.RestartPolicy = ExtractorRestartPolicy.OnError;
216+
217+
using var evt = new ManualResetEventSlim(false);
218+
using var source = new CancellationTokenSource();
219+
220+
var (extractor, runtime) = await createExtractorForRestartTest(evt, builder, source.Token);
216221

217-
// Wait for a startup to be reported.
218222
await TestUtils.WaitForCondition(() => _startupCount == 1, 5);
219223

220224
// Update the config revision and the extractor should be restarted.
@@ -239,9 +243,43 @@ public async Task TestRuntimeRestartNewConfig()
239243
// Finally, shut down the extractor.
240244
source.Cancel();
241245

242-
await runTask;
246+
await runtime.Run();
243247
}
244248

249+
[Fact(Timeout = 5000)]
250+
public async Task TestNeverRestartPolicy()
251+
{
252+
var builder = CreateMockRuntimeBuilder();
253+
// Restart policy won't be the default "Always" in customer envs, but we should
254+
// still restart on config change.
255+
builder.RestartPolicy = ExtractorRestartPolicy.Never;
256+
257+
using var evt = new ManualResetEventSlim(false);
258+
using var source = new CancellationTokenSource();
259+
260+
var (extractor, runtime) = await createExtractorForRestartTest(evt, builder, source.Token);
261+
// Wait for a startup to be reported.
262+
await TestUtils.WaitForCondition(() => _startupCount == 1, 5);
263+
264+
// Update the config revision and the extractor should be restarted.
265+
var oldExtractor = extractor;
266+
extractor = null;
267+
evt.Reset();
268+
_responseRevision = new ConfigRevision
269+
{
270+
Revision = 2,
271+
Config = "foo: baz"
272+
};
273+
274+
// Flush the sink to speed things along
275+
await oldExtractor.Sink.Flush(source.Token);
276+
277+
// Extractor should not be restarted, so we should time out waiting for the event to be set.
278+
Assert.False(await CommonUtils.WaitAsync(evt.WaitHandle, TimeSpan.FromSeconds(1), source.Token));
279+
Assert.Null(extractor);
280+
}
281+
282+
245283
[Fact(Timeout = 5000)]
246284
public async Task TestRuntimeRestartExtractorCrash()
247285
{

ExtractorUtils/Unstable/Configuration/ConfigSource.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public override async Task<bool> ResolveConfig(int? targetRevision, BaseErrorRep
155155
var msg = ex.Message;
156156
if (_lastErrorMsg != msg)
157157
{
158-
reporter.Fatal($"Fatally failed to load configuration file from {_configFilePath}: {ex.Message}");
158+
reporter.Fatal($"Fatally failed to load configuration file {_configFilePath}: {ex.Message}", ex.Message + "\n" + ex.StackTrace);
159159
}
160160
_lastErrorMsg = msg;
161161
throw;
@@ -170,7 +170,7 @@ public override async Task<bool> ResolveConfig(int? targetRevision, BaseErrorRep
170170
{
171171
if (isNewConfig)
172172
{
173-
reporter.Fatal($"Failed to parse configuration file from {_configFilePath}: {ex.Message}");
173+
reporter.Fatal($"Failed to parse configuration file {_configFilePath}: {ex.Message}", ex.Message + "\n" + ex.StackTrace);
174174
}
175175
throw;
176176
}
@@ -256,7 +256,7 @@ public override async Task<bool> ResolveConfig(int? targetRevision, BaseErrorRep
256256
var msg = ex.Message;
257257
if (_lastErrorMsg != msg)
258258
{
259-
reporter.Fatal($"Fatally failed to load configuration file from CDF: {msg}");
259+
reporter.Fatal($"Fatally failed to load0 configuration file from CDF: {msg}", msg + "\n" + ex.StackTrace);
260260
}
261261
_lastErrorMsg = msg;
262262
throw;
@@ -275,7 +275,7 @@ public override async Task<bool> ResolveConfig(int? targetRevision, BaseErrorRep
275275
{
276276
if (isNewConfig)
277277
{
278-
reporter.Fatal($"Failed to parse configuration file from CDF: {ex.Message}");
278+
reporter.Fatal($"Failed to parse configuration file from CDF: {ex.Message}", ex.Message + "\n" + ex.StackTrace);
279279
}
280280
throw;
281281
}

0 commit comments

Comments
 (0)