private State Launch(ITestOutputHelper output, DaprRunConfiguration configuration) { var app = new DaprTestApp(output, configuration.AppId); try { var(httpEndpoint, grpcEndpoint) = app.Start(configuration); return(new State() { App = app, HttpEndpoint = httpEndpoint, GrpcEndpoint = grpcEndpoint, Output = output, }); } catch (Exception startException) { try { app.Stop(); throw; } catch (Exception stopException) { throw new AggregateException(startException, stopException); } } }
public Task <State> StartAsync(ITestOutputHelper output, DaprRunConfiguration configuration) { lock (@lock) { if (this.task is null) { this.task = Task.Run(() => Launch(output, configuration)); } return(this.task); } }
public (string httpEndpoint, string grpcEndpoint) Start(DaprRunConfiguration configuration) { var(appPort, httpPort, grpcPort, metricsPort) = GetFreePorts(); var componentsPath = Combine(".", "..", "..", "..", "..", "..", "test", "Dapr.E2E.Test", "components"); var configPath = Combine(".", "..", "..", "..", "..", "..", "test", "Dapr.E2E.Test", "configuration", "featureconfig.yaml"); var arguments = new List <string>() { // `dapr run` args "run", "--app-id", configuration.AppId, "--dapr-http-port", httpPort.ToString(CultureInfo.InvariantCulture), "--dapr-grpc-port", grpcPort.ToString(CultureInfo.InvariantCulture), "--metrics-port", metricsPort.ToString(CultureInfo.InvariantCulture), "--components-path", componentsPath, "--config", configPath, "--log-level", "debug", }; if (configuration.UseAppPort) { arguments.AddRange(new[] { "--app-port", appPort.ToString(CultureInfo.InvariantCulture), }); } if (!string.IsNullOrEmpty(configuration.AppProtocol)) { arguments.AddRange(new [] { "--app-protocol", configuration.AppProtocol }); } arguments.AddRange(new[] { // separator "--", // `dotnet run` args "dotnet", "run", "--project", configuration.TargetProject, "--framework", GetTargetFrameworkName(), }); if (configuration.UseAppPort) { // The first argument is the port, if the application needs it. arguments.AddRange(new[] { "--", $"{appPort.ToString(CultureInfo.InvariantCulture)}" }); arguments.AddRange(new[] { "--urls", $"http://localhost:{appPort.ToString(CultureInfo.InvariantCulture)}", }); } // TODO: we don't do any quoting right now because our paths are guaranteed not to contain spaces var daprStart = new DaprCommand(this.testOutput) { DaprBinaryName = DaprTestApp.daprBinaryName, Command = string.Join(" ", arguments), OutputToMatch = outputToMatchOnStart, Timeout = TimeSpan.FromSeconds(30), }; daprStart.Run(); testOutput.WriteLine($"Dapr app: {appId} started successfully"); var httpEndpoint = $"http://localhost:{httpPort}"; var grpcEndpoint = $"http://localhost:{grpcPort}"; return(httpEndpoint, grpcEndpoint); }