Skip to content

Commit 19b2c5d

Browse files
committed
fix test
1 parent d331f2b commit 19b2c5d

File tree

2 files changed

+19
-57
lines changed

2 files changed

+19
-57
lines changed

ExtractorUtils.Test/unit/Unstable/RuntimeTest.cs

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

189-
private async Task<(DummyExtractor, ExtractorRuntime<DummyConfig, DummyExtractor>)> createExtractorForRestartTest(ManualResetEventSlim evt, ExtractorRuntimeBuilder<DummyConfig, DummyExtractor> builder, CancellationToken token)
189+
[Fact(Timeout = 5000)]
190+
public async Task TestRuntimeRestartNewConfig()
190191
{
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+
191199
DummyExtractor extractor = null;
192200
builder.OnCreateExtractor = (_, ext) =>
193201
{
@@ -198,27 +206,15 @@ private ExtractorRuntimeBuilder<DummyConfig, DummyExtractor> CreateMockRuntimeBu
198206
};
199207
};
200208

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

204-
Assert.True(await CommonUtils.WaitAsync(evt.WaitHandle, TimeSpan.FromSeconds(5), token));
214+
Assert.True(await CommonUtils.WaitAsync(evt.WaitHandle, TimeSpan.FromSeconds(5), source.Token));
205215
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);
221216

217+
// Wait for a startup to be reported.
222218
await TestUtils.WaitForCondition(() => _startupCount == 1, 5);
223219

224220
// Update the config revision and the extractor should be restarted.
@@ -243,43 +239,9 @@ public async Task TestRuntimeRestartNewConfig()
243239
// Finally, shut down the extractor.
244240
source.Cancel();
245241

246-
await runtime.Run();
247-
}
248-
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);
242+
await runTask;
280243
}
281244

282-
283245
[Fact(Timeout = 5000)]
284246
public async Task TestRuntimeRestartExtractorCrash()
285247
{

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 {_configFilePath}: {ex.Message}", ex.Message + "\n" + ex.StackTrace);
158+
reporter.Fatal($"Fatally failed to load configuration file from {_configFilePath}: {ex.Message}");
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 {_configFilePath}: {ex.Message}", ex.Message + "\n" + ex.StackTrace);
173+
reporter.Fatal($"Failed to parse configuration file from {_configFilePath}: {ex.Message}");
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 load0 configuration file from CDF: {msg}", msg + "\n" + ex.StackTrace);
259+
reporter.Fatal($"Fatally failed to load configuration file from CDF: {msg}");
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}", ex.Message + "\n" + ex.StackTrace);
278+
reporter.Fatal($"Failed to parse configuration file from CDF: {ex.Message}");
279279
}
280280
throw;
281281
}

0 commit comments

Comments
 (0)