public async Task RestartServerAsync(Context context) { if (_doNotStartService) { throw new InvalidOperationException(); } await _serviceProcess.ShutdownAsync(context).ShouldBeSuccess(); _serviceProcess.Dispose(); _serviceProcess = new ServiceProcess(_configuration, _localContentServerConfiguration, Configuration.Scenario, WaitForServerReadyTimeoutMs, WaitForExitTimeoutMs); await _serviceProcess.StartupAsync(context).ShouldBeSuccess(); }
protected override async Task <BoolResult> PreStartupAsync(Context context) { _logger.Debug($"{nameof(TestServiceClientContentStore)}.{nameof(PreStartupAsync)} _doNotStartService={_doNotStartService}"); if (_doNotStartService) { return(BoolResult.Success); } var r = await _serviceProcess.StartupAsync(context); if (r.Succeeded) { if (!(await Task.Run(() => LocalContentServer.EnsureRunning(context, Configuration.Scenario, 10000)))) { return(new BoolResult("Failed to detect server ready in separate process")); } } return(r); }
private async Task RunServerTestAsync(Context context, Func <Context, ServiceConfiguration, Task> funcAsync) { using (var directory = new DisposableDirectory(FileSystem)) { var storeConfig = CreateStoreConfiguration(); await storeConfig.Write(FileSystem, directory.Path).ConfigureAwait(false); var serviceConfig = CreateServiceConfiguration(directory.Path, PortExtensions.GetNextAvailablePort(), Guid.NewGuid().ToString()); using (var server = new ServiceProcess(serviceConfig, LocalContentServerConfiguration, Scenario, WaitForServerReadyTimeoutMs, WaitForExitTimeoutMs)) { BoolResult r = await server.StartupAsync(context).ConfigureAwait(false); r.ShouldBeSuccess(); await funcAsync(context, serviceConfig); r = await server.ShutdownAsync(context); r.ShouldBeSuccess(); } } }
public async Task TestPutThenPlace() { if (string.IsNullOrEmpty(GetConnectionString())) { // Only run this test if the connection string is defined Console.WriteLine("Couldn't find connection string!"); return; } Console.WriteLine("Found connection string!"); var context = new Context(TestGlobal.Logger); using (var d = new DisposableDirectory(FileSystem)) { string ringId = GetRandomFileName(); string stampId = GetRandomFileName(); // Define cache 1 var distributedConfig1 = CreateRandomDistributedConfig(d, stampId, ringId); var putScenario = ThreadSafeRandom.Generator.Next().ToString(); var cacheProcess1 = new ServiceProcess(distributedConfig1, putScenario, ReadyWaitMs, ShutdownWaitMs); // Define cache 2 var distributedConfig2 = CreateRandomDistributedConfig(d, stampId, ringId); var placeScenario = ThreadSafeRandom.Generator.Next().ToString(); var cacheProcess2 = new ServiceProcess(distributedConfig2, placeScenario, ReadyWaitMs, ShutdownWaitMs); using (cacheProcess1) using (cacheProcess2) { try { // Startup cache 1 await cacheProcess1.StartupAsync(context).ShouldBeSuccess(); Logger.Debug(cacheProcess1.GetLogs()); try { // Startup cache 2 await cacheProcess2.StartupAsync(context).ShouldBeSuccess(); Logger.Debug(cacheProcess2.GetLogs()); // Generate random file var bytes = ThreadSafeRandom.GetBytes(1024); var filePath = d.Path / GetRandomFileName(); await FileUtilities.WriteAllBytesAsync(filePath.Path, bytes); var contentHash = bytes.CalculateHash(HashType.Vso0); // Ensure the GRPC servers have successfully spun up var boolResults = await Task.WhenAll(CheckGrpcPortIsOpen(context, distributedConfig1.GrpcPort), CheckGrpcPortIsOpen(context, distributedConfig2.GrpcPort)); boolResults.Select(br => br.ShouldBeSuccess()); // Put random file into cache 1 var putConfiguration = new PutConfiguration( contentHash.HashType, filePath, distributedConfig1.GrpcPort, distributedConfig1.CacheName, null); var putProcess = new ServiceProcess(putConfiguration, putScenario, ReadyWaitMs, ShutdownWaitMs, true); using (putProcess) { try { await putProcess.StartupAsync(context).ShouldBeSuccess(); Logger.Debug(putProcess.GetLogs()); await Task.Delay(ReadyWaitMs); } finally { await putProcess.ShutdownAsync(context).ShouldBeSuccess(); Logger.Debug(putProcess.GetLogs()); } } // Place random file from cache 2 // Cache 2 should: // * Fail to find the content for the given hash in the local cache // * Ask redis if the content exists elsewhere, find that cache 1 has it // * Copy the content from cache 1's local cache into cache 2's local cache // * Place the content from cache 2's local cache to the requested path var placeConfiguration = new PlaceConfiguration( contentHash, d.Path / GetRandomFileName(), distributedConfig2.GrpcPort, distributedConfig2.CacheName, null); var placeProcess = new ServiceProcess(placeConfiguration, placeScenario, ReadyWaitMs, ShutdownWaitMs, true); using (placeProcess) { try { await placeProcess.StartupAsync(context).ShouldBeSuccess(); Logger.Debug(placeProcess.GetLogs()); } finally { await placeProcess.ShutdownAsync(context).ShouldBeSuccess(); Logger.Debug(placeProcess.GetLogs()); } } } finally { // Shutdown cache 2 if (cacheProcess2 != null) { var shutdownResult2 = await cacheProcess2.ShutdownAsync(context); Logger.Debug(cacheProcess2.GetLogs()); } } } finally { // Shutdown cache 1 if (cacheProcess1 != null) { var shutdownResult1 = await cacheProcess1.ShutdownAsync(context); Logger.Debug(cacheProcess1.GetLogs()); } } } } }