51 lines
1.9 KiB
C#
51 lines
1.9 KiB
C#
using VolcanicCore.Persistence;
|
|
using VolcanicCore.Persistence.Migrations;
|
|
using VolcanicCore.Persistence.Repositories;
|
|
|
|
namespace VolcanicCore.Tests;
|
|
|
|
public class NodeExecutionRepositoryTests
|
|
{
|
|
private static (ExecutionRepository ex, NodeExecutionRepository ne) Setup()
|
|
{
|
|
var path = Path.Combine(Path.GetTempPath(), $"vc-{Guid.NewGuid():N}.db");
|
|
var f = new SqliteConnectionFactory(path);
|
|
using (var conn = f.Open())
|
|
new Migrator(new IMigration[]
|
|
{
|
|
new Migration001Initial(),
|
|
new Migration002Connections(),
|
|
new Migration003Workflows(),
|
|
new Migration004Executions(),
|
|
new Migration005NodeExecutions(),
|
|
}).Apply(conn);
|
|
return (new ExecutionRepository(f), new NodeExecutionRepository(f));
|
|
}
|
|
|
|
[Fact]
|
|
public void Create_and_list_by_execution()
|
|
{
|
|
var (ex, ne) = Setup();
|
|
var eid = ex.Create("wf1", "manual", "{}");
|
|
var start = DateTimeOffset.UtcNow;
|
|
ne.Create(eid, "n1", "[]", "[[]]", "completed", start, start.AddMilliseconds(3), null);
|
|
ne.Create(eid, "n2", "[[]]", "[]", "failed", start, start.AddMilliseconds(5), "boom");
|
|
|
|
var list = ne.ListByExecution(eid);
|
|
Assert.Equal(2, list.Count);
|
|
Assert.Contains(list, x => x.NodeId == "n1" && x.Status == "completed");
|
|
Assert.Contains(list, x => x.NodeId == "n2" && x.Status == "failed" && x.Error == "boom");
|
|
}
|
|
|
|
[Fact]
|
|
public void Cascade_delete_removes_rows_when_execution_deleted()
|
|
{
|
|
var (ex, ne) = Setup();
|
|
var eid = ex.Create("wf1", "manual", "{}");
|
|
ne.Create(eid, "n1", "[]", "[[]]", "completed", DateTimeOffset.UtcNow, DateTimeOffset.UtcNow, null);
|
|
ex.SetStatus(eid, "completed", null, DateTimeOffset.UtcNow);
|
|
Assert.Equal(1, ex.PruneOldestPerWorkflow(keep: 0));
|
|
Assert.Empty(ne.ListByExecution(eid));
|
|
}
|
|
}
|