Skip to content

Commit ca68897

Browse files
committed
Fix test warning, add exit code
1 parent d9d1cd6 commit ca68897

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

src/WebJobs.Script.Grpc/Channel/GrpcWorkerChannel.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
using Microsoft.Azure.WebJobs.Script.Diagnostics;
2424
using Microsoft.Azure.WebJobs.Script.Diagnostics.OpenTelemetry;
2525
using Microsoft.Azure.WebJobs.Script.Eventing;
26-
using Microsoft.Azure.WebJobs.Script.Exceptions;
2726
using Microsoft.Azure.WebJobs.Script.Extensions;
2827
using Microsoft.Azure.WebJobs.Script.Grpc.Eventing;
2928
using Microsoft.Azure.WebJobs.Script.Grpc.Extensions;
@@ -388,14 +387,17 @@ public async Task StartWorkerProcessAsync(CancellationToken cancellationToken)
388387
_workerChannelLogger.LogDebug("Initiating Worker Process start up");
389388
await _rpcWorkerProcess.StartProcessAsync(cancellationToken);
390389
_state |= RpcWorkerChannelState.Initializing;
391-
Task exited = _rpcWorkerProcess.WaitForExitAsync(cancellationToken);
390+
Task<int> exited = _rpcWorkerProcess.WaitForExitAsync(cancellationToken);
392391
Task winner = await Task.WhenAny(_workerInitTask.Task, exited).WaitAsync(cancellationToken);
393392
await winner;
394393

395394
if (winner == exited)
396395
{
397-
// process exited without throwing. We need to throw to indicate process is not running.
398-
throw new WorkerProcessExitException("Worker process exited before initializing.");
396+
// Process exited without throwing. We need to throw to indicate process is not running.
397+
throw new WorkerProcessExitException("Worker process exited before initializing.")
398+
{
399+
ExitCode = await exited,
400+
};
399401
}
400402
}
401403

src/WebJobs.Script/Workers/ProcessManagement/IWorkerProcess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface IWorkerProcess
1515

1616
Task StartProcessAsync(CancellationToken cancellationToken = default);
1717

18-
Task WaitForExitAsync(CancellationToken cancellationToken = default);
18+
Task<int> WaitForExitAsync(CancellationToken cancellationToken = default);
1919

2020
void WaitForProcessExitInMilliSeconds(int waitTime);
2121
}

src/WebJobs.Script/Workers/ProcessManagement/WorkerProcess.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ internal abstract class WorkerProcess : IWorkerProcess, IDisposable
3838
private readonly bool _useStdErrorStreamForErrorsOnly;
3939
private Queue<string> _processStdErrDataQueue = new(3);
4040
private IHostProcessMonitor _processMonitor;
41-
private TaskCompletionSource _processExit; // used to hold custom exceptions on non-success exit.
41+
private TaskCompletionSource<int> _processExit; // used to hold custom exceptions on non-success exit.
4242

4343
internal WorkerProcess(IScriptEventManager eventManager, IProcessRegistry processRegistry, ILogger workerProcessLogger, IWorkerConsoleLogSource consoleLogSource, IMetricsLogger metricsLogger,
4444
IServiceProvider serviceProvider, ILoggerFactory loggerFactory, IEnvironment environment, IOptionsMonitor<ScriptApplicationHostOptions> scriptApplicationHostOptions, bool useStdErrStreamForErrorsOnly = false)
@@ -114,8 +114,9 @@ public Task StartProcessAsync(CancellationToken cancellationToken = default)
114114
}
115115
}
116116

117-
public Task WaitForExitAsync(CancellationToken cancellationToken = default)
117+
public Task<int> WaitForExitAsync(CancellationToken cancellationToken = default)
118118
{
119+
ObjectDisposedException.ThrowIf(Disposing, this);
119120
if (_processExit is { } tcs)
120121
{
121122
// We use a TaskCompletionSource (and not Process.WaitForExitAsync) so we can propagate our custom exceptions.
@@ -201,7 +202,7 @@ private void OnProcessExited(object sender, EventArgs e)
201202
}
202203
finally
203204
{
204-
_processExit.TrySetResult();
205+
_processExit.TrySetResult(Process.ExitCode);
205206
UnregisterFromProcessMonitor();
206207
Process.Close();
207208
}
@@ -375,7 +376,7 @@ private void AssignUserExecutePermissionsIfNotExists()
375376
return;
376377
}
377378

378-
UnixFileInfo fileInfo = new UnixFileInfo(filePath);
379+
UnixFileInfo fileInfo = new(filePath);
379380
if (!fileInfo.FileAccessPermissions.HasFlag(FileAccessPermissions.UserExecute))
380381
{
381382
_workerProcessLogger.LogDebug("Assigning execute permissions to file: {filePath}", filePath);

test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,11 @@ public async Task GetExtensionsStartupTypes_EmptyExtensionsArray()
616616
AssertNoErrors(traces);
617617
}
618618

619+
private static void AssertNoErrors(IList<LogMessage> traces)
620+
{
621+
Assert.False(traces.Any(m => m.Level == LogLevel.Error || m.Level == LogLevel.Critical));
622+
}
623+
619624
private static ExtensionBundleDetails GetBundleDetails(string version = "2.7.0")
620625
{
621626
return new ExtensionBundleDetails
@@ -751,10 +756,5 @@ public void CopyTo(string path)
751756
}
752757
}
753758
}
754-
755-
private static void AssertNoErrors(IList<LogMessage> traces)
756-
{
757-
Assert.False(traces.Any(m => m.Level == LogLevel.Error || m.Level == LogLevel.Critical));
758-
}
759759
}
760760
}

0 commit comments

Comments
 (0)