public async Task Run(IDictionary <string, string> environmentVariables, CancellationToken token = default) { if (environmentVariables == null) { throw new ArgumentNullException(nameof(environmentVariables)); } // Make sure that we don't try to add the same var twice. var stringifiedVariables = EnvironmentVariables.MergeDictionaries(environmentVariables) .Select(p => $"{p.Key}={p.Value}").ToArray(); await RunContainerSafely(stringifiedVariables, token); if (_containerWaiter != null) { var isStarted = await _containerWaiter.Wait(this, token); if (!isStarted) { Logger.LogError($"Container {Name} didn't start."); throw new TimeoutException($"Container {Name} didn't start."); } } if (_containerInitializer != null) { await _containerInitializer.Initialize(this, token); } if (_reuseContainer && _containerCleaner != null) { await _containerCleaner.Cleanup(this, token); } }
private async Task WaitForReadiness(CancellationToken token = default) { var attempts = AttemptsCount; var isAlive = false; do { isAlive = await _containerWaiter.Wait(this, token); if (!isAlive) { attempts--; await Task.Delay(DelayTime); } }while (!isAlive && attempts != 0); if (attempts == 0) { Logger.LogError($"Container {Name} didn't start."); throw new TimeoutException($"Container {Name} didn't start."); } }