public Task AddCachedTestResult(AssemblyInfo assemblyInfo, ContentFile contentFile, CachedTestResult testResult) { var checksum = contentFile.Checksum; var storagePath = Path.Combine(_storagePath, checksum); try { if (!FileUtil.EnsureDirectory(storagePath)) { return(Task.FromResult(true)); } Write(checksum, StorageKind.ExitCode, testResult.ExitCode.ToString()); Write(checksum, StorageKind.StandardOutput, testResult.StandardOutput); Write(checksum, StorageKind.ErrorOutput, testResult.ErrorOutput); Write(checksum, StorageKind.ResultsFileContent, testResult.ResultsFileContent); Write(checksum, StorageKind.ElapsedSeconds, testResult.Elapsed.TotalSeconds.ToString()); Write(checksum, StorageKind.Content, contentFile.Content); } catch (Exception e) { // I/O errors are expected and okay here. Logger.Log($"Failed to log {checksum} {e.Message}"); FileUtil.DeleteDirectory(storagePath); } return(Task.FromResult(true)); }
public void AddTestResult(ContentFile contentFile, TestResult testResult) { var checksum = contentFile.Checksum; var storagePath = Path.Combine(_storagePath, checksum); try { if (!FileUtil.EnsureDirectory(storagePath)) { return; } Write(checksum, StorageKind.ExitCode, testResult.ExitCode.ToString()); Write(checksum, StorageKind.AssemblyPath, testResult.AssemblyPath); Write(checksum, StorageKind.StandardOutput, testResult.StandardOutput); Write(checksum, StorageKind.ErrorOutput, testResult.ErrorOutput); Write(checksum, StorageKind.CommandLine, testResult.CommandLine); Write(checksum, StorageKind.Content, contentFile.Content); if (!string.IsNullOrEmpty(testResult.ResultsFilePath)) { File.Copy(testResult.ResultsFilePath, GetStoragePath(checksum, StorageKind.ResultsFile)); } } catch (Exception e) { // I/O errors are expected and okay here. Logger.Log($"Failed to log {checksum} {e.Message}"); FileUtil.DeleteDirectory(storagePath); } }
public async Task AddCachedTestResult(AssemblyInfo assemblyInfo, ContentFile contentFile, CachedTestResult testResult) { try { var obj = new JObject(); obj["TestResultData"] = CreateTestResultData(assemblyInfo.ResultsFileName, testResult); obj["TestSourceData"] = CreateTestSourceData(assemblyInfo); var request = new RestRequest($"api/testcache/{contentFile.Checksum}"); request.Method = Method.PUT; request.RequestFormat = DataFormat.Json; request.AddParameter("text/json", obj.ToString(), ParameterType.RequestBody); var response = await _restClient.ExecuteTaskAsync(request); if (response.StatusCode != HttpStatusCode.NoContent) { Logger.Log($"Error adding web cached result: {response.StatusCode}"); } } catch (Exception ex) { Logger.Log($"Exception adding web cached result: {ex}"); } }
public Task AddCachedTestResult(string assemblyName, ContentFile conentFile, CachedTestResult testResult) { var source = new TaskCompletionSource <bool>(); source.SetResult(true); return(source.Task); }
public async Task AddCachedTestResult(string assemblyName, ContentFile contentFile, CachedTestResult testResult) { var obj = new JObject(); obj["TestResultData"] = CreateTestResultData(testResult); obj["TestSourceData"] = CreateTestSourceData(assemblyName); var request = new RestRequest($"api/testcache/{contentFile.Checksum}"); request.Method = Method.PUT; request.RequestFormat = DataFormat.Json; request.AddParameter("text/json", obj.ToString(), ParameterType.RequestBody); var response = await _restClient.ExecuteTaskAsync(request); }
private async Task CacheTestResult(ContentFile contentFile, TestResult testResult) { try { var resultFileContent = File.ReadAllText(testResult.ResultsFilePath); var cachedTestResult = new CachedTestResult( exitCode: testResult.ExitCode, standardOutput: testResult.StandardOutput, errorOutput: testResult.ErrorOutput, resultsFileContent: resultFileContent, elapsed: testResult.Elapsed); await _dataStorage.AddCachedTestResult(testResult.AssemblyInfo, contentFile, cachedTestResult).ConfigureAwait(true); } catch (Exception ex) { Logger.Log($"Failed to create cached {ex}"); } }
private void CacheTestResult(ContentFile contentFile, TestResult testResult) { try { var resultFileContent = File.ReadAllText(testResult.ResultsFilePath); var cachedTestResult = new CachedTestResult( exitCode: testResult.ExitCode, standardOutput: testResult.StandardOutput, errorOutput: testResult.ErrorOutput, resultsFileName: Path.GetFileName(testResult.ResultsFilePath), resultsFileContent: resultFileContent); _dataStorage.AddCachedTestResult(contentFile, cachedTestResult); } catch (Exception ex) { Logger.Log($"Failed to create cached {ex}"); } }
public async Task AddCachedTestResult(AssemblyInfo assemblyInfo, ContentFile contentFile, CachedTestResult testResult) { try { var testCacheData = CreateTestCacheData(assemblyInfo, assemblyInfo.ResultsFileName, testResult); var request = new RestRequest($"api/testData/cache/{contentFile.Checksum}"); request.Method = Method.PUT; request.RequestFormat = DataFormat.Json; request.AddParameter("text/json", JsonConvert.SerializeObject(testCacheData), ParameterType.RequestBody); var response = await _restClient.ExecuteTaskAsync(request); if (response.StatusCode != HttpStatusCode.NoContent) { Logger.Log($"Error adding web cached result: {response.StatusCode}"); } } catch (Exception ex) { Logger.LogError(ex, "Exception uploading cached test result"); } }
private async Task <TestResult> RunTestWithCachingAsync(AssemblyInfo assemblyInfo, ContentFile contentFile, CancellationToken cancellationToken) { var assemblyPath = assemblyInfo.AssemblyPath; var builder = new StringBuilder(); builder.AppendLine($"{Path.GetFileName(assemblyPath)} - {contentFile.Checksum}"); builder.AppendLine("==="); builder.AppendLine(contentFile.Content); builder.AppendLine("==="); Logger.Log(builder.ToString()); try { var cachedTestResult = await _dataStorage.TryGetCachedTestResult(contentFile.Checksum); if (cachedTestResult.HasValue) { Logger.Log($"{Path.GetFileName(assemblyPath)} - cache hit"); return(Migrate(assemblyInfo, cachedTestResult.Value)); } } catch (Exception ex) { Logger.Log($"Error reading cache {ex}"); } Logger.Log($"{Path.GetFileName(assemblyPath)} - running"); var testResult = await _testExecutor.RunTestAsync(assemblyInfo, cancellationToken); await CacheTestResult(contentFile, testResult).ConfigureAwait(true); return(testResult); }
public Task AddCachedTestResult(AssemblyInfo assemblyInfo, ContentFile conentFile, CachedTestResult testResult) { var source = new TaskCompletionSource<bool>(); source.SetResult(true); return source.Task; }
public Task AddCachedTestResult(AssemblyInfo assemblyInfo, ContentFile contentFile, CachedTestResult testResult) { var checksum = contentFile.Checksum; var storagePath = Path.Combine(_storagePath, checksum); try { if (!FileUtil.EnsureDirectory(storagePath)) { return Task.FromResult(true); } Write(checksum, StorageKind.ExitCode, testResult.ExitCode.ToString()); Write(checksum, StorageKind.StandardOutput, testResult.StandardOutput); Write(checksum, StorageKind.ErrorOutput, testResult.ErrorOutput); Write(checksum, StorageKind.ResultsFileContent, testResult.ResultsFileContent); Write(checksum, StorageKind.ElapsedSeconds, testResult.Elapsed.TotalSeconds.ToString()); Write(checksum, StorageKind.Content, contentFile.Content); } catch (Exception e) { // I/O errors are expected and okay here. Logger.Log($"Failed to log {checksum} {e.Message}"); FileUtil.DeleteDirectory(storagePath); } return Task.FromResult(true); }