[xharness] Write intermediate html reports to disk when running in server mode too. (#5193)

That way the report is still available even if xharness dies.

Also improve report generation to write directly to a temporary file on disk,
instead of writing to memory and then writing to disk (improves memory usage).
This commit is contained in:
Rolf Bjarne Kvinge 2018-11-28 15:02:30 +01:00 коммит произвёл GitHub
Родитель 1dee193134
Коммит 95a4b9a2a1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 15 добавлений и 22 удалений

Просмотреть файл

@ -1355,33 +1355,26 @@ namespace xharness
}
object report_lock = new object ();
public void GenerateReport (bool only_if_ci = false)
public void GenerateReport ()
{
if (only_if_ci && IsServerMode)
return;
try {
lock (report_lock) {
var report = Path.Combine (LogDirectory, "index.html");
using (var stream = new MemoryStream ()) {
MemoryStream markdown_summary = null;
StreamWriter markdown_writer = null;
if (!string.IsNullOrEmpty (Harness.MarkdownSummaryPath)) {
markdown_summary = new MemoryStream ();
markdown_writer = new StreamWriter (markdown_summary);
}
GenerateReportImpl (stream, markdown_writer);
if (File.Exists (report))
File.Delete (report);
File.WriteAllBytes (report, stream.ToArray ());
if (!string.IsNullOrEmpty (Harness.MarkdownSummaryPath)) {
markdown_writer.Flush ();
if (File.Exists (Harness.MarkdownSummaryPath))
File.Delete (Harness.MarkdownSummaryPath);
File.WriteAllBytes (Harness.MarkdownSummaryPath, markdown_summary.ToArray ());
markdown_writer.Close ();
var tmpreport = Path.Combine (LogDirectory, $"index-{Harness.Timestamp}.tmp.html");
var tmpmarkdown = string.IsNullOrEmpty (Harness.MarkdownSummaryPath) ? string.Empty : (Harness.MarkdownSummaryPath + $".{Harness.Timestamp}.tmp");
using (var stream = new FileStream (tmpreport, FileMode.CreateNew, FileAccess.ReadWrite)) {
using (var markdown_writer = (string.IsNullOrEmpty (tmpmarkdown) ? null : new StreamWriter (tmpmarkdown))) {
GenerateReportImpl (stream, markdown_writer);
}
}
if (File.Exists (report))
File.Delete (report);
File.Move (tmpreport, report);
if (!string.IsNullOrEmpty (tmpmarkdown)) {
if (File.Exists (Harness.MarkdownSummaryPath))
File.Delete (Harness.MarkdownSummaryPath);
File.Move (tmpmarkdown, Harness.MarkdownSummaryPath);
}
}
} catch (Exception e) {
this.MainLog.WriteLine ("Failed to write log: {0}", e);
@ -2490,7 +2483,7 @@ function toggleAll (show)
duration.Stop ();
}
Jenkins.GenerateReport (true);
Jenkins.GenerateReport ();
}
protected virtual void PropagateResults ()