using System.Collections.Specialized;
using System.Text.Json.Nodes;
using XFEWorkflow.Abstractions;
using XFEWorkflow.Infrastructure.Storage;
using XFEWorkflow.Services;
namespace XFEWorkflow.Views;
public sealed partial class MainPage
{
internal async Task SmokeRunFloodAsync(string output)
{
await ready.Task; var previous = ViewModel.SelectedWorkflow;
var workflow = new WorkflowDefinition { Name = "后台日志压力验收", Code = "", Graph = Core.Runtime.WorkflowTemplates.EmptyGraph() };
var body = new NodeDefinition { Id = "flood", CapabilityId = "core.csharp", Name = "后台产生大量日志", Code = "for (var i = 0; i < 5000; i++) await context.LogAsync(\"压力日志 \" + i, cancellationToken); await Task.Delay(300, cancellationToken); return new JsonObject();", X = 400 };
workflow.Graph.Nodes.Insert(1, body); workflow.Graph.Edges.Clear();
workflow.Graph.Edges.Add(new() { FromNode = workflow.Graph.Nodes[0].Id, ToNode = body.Id });
workflow.Graph.Edges.Add(new() { FromNode = body.Id, ToNode = workflow.Graph.Nodes[^1].Id });
var pulses = 0; var notifications = 0; var maxGap = TimeSpan.Zero; var last = DateTime.UtcNow;
var pulse = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(25) };
pulse.Tick += (_, _) => { var now = DateTime.UtcNow; if (now - last > maxGap) maxGap = now - last; last = now; pulses++; };
NotifyCollectionChangedEventHandler changed = (_, _) => notifications++;
try
{
await ViewModel.NewAsync(workflow); await Task.Delay(350); CanvasEditor.CenterView(true); await Task.Delay(350);
var before = CanvasEditor.InspectViewport(); var refreshes = runUiRefreshCount;
ViewModel.RunLines.CollectionChanged += changed; pulse.Start(); runUpdateTimer.Start();
var run = await services.Runs.RunAsync(workflow).WaitAsync(TimeSpan.FromSeconds(35));
await FlushRunUpdateAsync(); await Task.Delay(200);
pulse.Stop();
var after = CanvasEditor.InspectViewport();
await AtomicJson.WriteAsync(Path.Combine(output, "run-ui-log-flood.json"), new { pulses, maxGapMilliseconds = maxGap.TotalMilliseconds, notifications, refreshes = runUiRefreshCount - refreshes, events = run.Events.Count, displayed = ViewModel.RunLines.Count, before, after });
if (run.Status != RunStatus.Succeeded) throw new InvalidOperationException(run.Error);
if (pulses < 3 || maxGap > TimeSpan.FromSeconds(2)) throw new InvalidOperationException($"后台工作流阻塞 UI:心跳 {pulses},最大间隔 {maxGap.TotalMilliseconds:0}ms");
if (ViewModel.RunLines.Count != 1000 || !ViewModel.RunLines.Any(x => x.LogText == "压力日志 4999")) throw new InvalidOperationException("输出未保留最新的有界日志快照");
if (notifications >= 100 || runUiRefreshCount - refreshes >= 100) throw new InvalidOperationException("日志洪峰仍逐条调度界面更新");
if (Math.Abs(before["horizontalOffset"]!.GetValue<double>() - after["horizontalOffset"]!.GetValue<double>()) > 2 || Math.Abs(before["verticalOffset"]!.GetValue<double>() - after["verticalOffset"]!.GetValue<double>()) > 2) throw new InvalidOperationException("后台节点通知改变画布视角");
await UiSmokeTest.CaptureWindowAsync(Path.Combine(output, "run-ui-log-flood.png"));
}
finally { pulse.Stop(); ViewModel.RunLines.CollectionChanged -= changed; ViewModel.SelectedWorkflow = previous; }
}
}
using System.Collections.Specialized;
using System.Text.Json.Nodes;
using XFEWorkflow.Abstractions;
using XFEWorkflow.Infrastructure.Storage;
using XFEWorkflow.Services;
namespace XFEWorkflow.Views;
public sealed partial class MainPage
{
internal async Task SmokeRunFloodAsync(string output)
{
await ready.Task; var previous = ViewModel.SelectedWorkflow;
var workflow = new WorkflowDefinition { Name = "后台日志压力验收", Code = "", Graph = Core.Runtime.WorkflowTemplates.EmptyGraph() };
var body = new NodeDefinition { Id = "flood", CapabilityId = "core.csharp", Name = "后台产生大量日志", Code = "for (var i = 0; i < 5000; i++) await context.LogAsync(\"压力日志 \" + i, cancellationToken); await Task.Delay(300, cancellationToken); return new JsonObject();", X = 400 };
workflow.Graph.Nodes.Insert(1, body); workflow.Graph.Edges.Clear();
workflow.Graph.Edges.Add(new() { FromNode = workflow.Graph.Nodes[0].Id, ToNode = body.Id });
workflow.Graph.Edges.Add(new() { FromNode = body.Id, ToNode = workflow.Graph.Nodes[^1].Id });
var pulses = 0; var notifications = 0; var maxGap = TimeSpan.Zero; var last = DateTime.UtcNow;
var pulse = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(25) };
pulse.Tick += (_, _) => { var now = DateTime.UtcNow; if (now - last > maxGap) maxGap = now - last; last = now; pulses++; };
NotifyCollectionChangedEventHandler changed = (_, _) => notifications++;
try
{
await ViewModel.NewAsync(workflow); await Task.Delay(350); CanvasEditor.CenterView(true); await Task.Delay(350);
var before = CanvasEditor.InspectViewport(); var refreshes = runUiRefreshCount;
ViewModel.RunLines.CollectionChanged += changed; pulse.Start(); runUpdateTimer.Start();
var run = await services.Runs.RunAsync(workflow).WaitAsync(TimeSpan.FromSeconds(35));
await FlushRunUpdateAsync(); await Task.Delay(200);
pulse.Stop();
var after = CanvasEditor.InspectViewport();
await AtomicJson.WriteAsync(Path.Combine(output, "run-ui-log-flood.json"), new { pulses, maxGapMilliseconds = maxGap.TotalMilliseconds, notifications, refreshes = runUiRefreshCount - refreshes, events = run.Events.Count, displayed = ViewModel.RunLines.Count, before, after });
if (run.Status != RunStatus.Succeeded) throw new InvalidOperationException(run.Error);
if (pulses < 3 || maxGap > TimeSpan.FromSeconds(2)) throw new InvalidOperationException($"后台工作流阻塞 UI:心跳 {pulses},最大间隔 {maxGap.TotalMilliseconds:0}ms");
if (ViewModel.RunLines.Count != 1000 || !ViewModel.RunLines.Any(x => x.LogText == "压力日志 4999")) throw new InvalidOperationException("输出未保留最新的有界日志快照");
if (notifications >= 100 || runUiRefreshCount - refreshes >= 100) throw new InvalidOperationException("日志洪峰仍逐条调度界面更新");
if (Math.Abs(before["horizontalOffset"]!.GetValue<double>() - after["horizontalOffset"]!.GetValue<double>()) > 2 || Math.Abs(before["verticalOffset"]!.GetValue<double>() - after["verticalOffset"]!.GetValue<double>()) > 2) throw new InvalidOperationException("后台节点通知改变画布视角");
await UiSmokeTest.CaptureWindowAsync(Path.Combine(output, "run-ui-log-flood.png"));
}
finally { pulse.Stop(); ViewModel.RunLines.CollectionChanged -= changed; ViewModel.SelectedWorkflow = previous; }
}
}