Skip to content

Commit 5e1d59b

Browse files
committed
InitialEffect: change Id from int to EffectId
Allows seeding nested-context effects in InitialState, not just root-level ones.
1 parent d8fefad commit 5e1d59b

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/FunctionTests/SunshineTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ await registration.Run(
356356
param: "hello",
357357
initialState: new InitialState(
358358
Messages: [new MessageAndIdempotencyKey("InitialMessage")],
359-
Effects: [new InitialEffect(Id: 0, Value: "InitialEffectValue", Exception: null, Alias: "InitialEffectId")]
359+
Effects: [new InitialEffect(Id: 0.ToEffectId(), Value: "InitialEffectValue", Exception: null, Alias: "InitialEffectId")]
360360
)
361361
);
362362

@@ -394,7 +394,7 @@ await registration.Run(
394394
param: "hello",
395395
initialState: new InitialState(
396396
Messages: [new MessageAndIdempotencyKey("InitialMessage")],
397-
Effects: [new InitialEffect(Id: 0, Value: "InitialEffectValue", Exception: null, Alias: "InitialEffectId")]
397+
Effects: [new InitialEffect(Id: 0.ToEffectId(), Value: "InitialEffectValue", Exception: null, Alias: "InitialEffectId")]
398398
)
399399
);
400400

@@ -431,7 +431,7 @@ await registration.Run(
431431
flowInstance: "hello",
432432
initialState: new InitialState(
433433
Messages: [new MessageAndIdempotencyKey("InitialMessage")],
434-
Effects: [new InitialEffect(Id: 0, Value: "InitialEffectValue", Exception: null, Alias: "InitialEffectId")]
434+
Effects: [new InitialEffect(Id: 0.ToEffectId(), Value: "InitialEffectValue", Exception: null, Alias: "InitialEffectId")]
435435
)
436436
);
437437

@@ -468,7 +468,7 @@ await registration.Run(
468468
flowInstance: "hello",
469469
initialState: new InitialState(
470470
Messages: [],
471-
Effects: [new InitialEffect(Id: "InitialEffectId".GetHashCode(), Status: WorkStatus.Started)]
471+
Effects: [new InitialEffect(Id: "InitialEffectId".GetHashCode().ToEffectId(), Status: WorkStatus.Started)]
472472
)
473473
);
474474

@@ -503,7 +503,7 @@ await registration.Run(
503503
flowInstance: "hello",
504504
initialState: new InitialState(
505505
Messages: [],
506-
Effects: [new InitialEffect(Id: 0, Exception: new TimeoutException())]
506+
Effects: [new InitialEffect(Id: 0.ToEffectId(), Exception: new TimeoutException())]
507507
)
508508
);
509509
Assert.Fail("Expected TimeoutException");

Core/Cleipnir.ResilientFunctions/CoreRuntime/Invocation/InvocationHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,14 @@ public IReadOnlyList<StoredEffect> MapInitialEffects(IEnumerable<InitialEffect>
470470
if (e.Value != null)
471471
resultBytes = Serializer.Serialize(e.Value, e.Value.GetType());
472472
return new StoredEffect(
473-
e.Id.ToEffectId(),
473+
e.Id,
474474
e.Status ?? WorkStatus.Completed,
475475
Result: resultBytes,
476476
StoredException: null,
477-
Alias: e.Alias ?? e.Id.ToString());
477+
Alias: e.Alias ?? e.Id.Serialize().ToStringValue());
478478
}
479479
return new StoredEffect(
480-
e.Id.ToEffectId(),
480+
e.Id,
481481
WorkStatus.Failed,
482482
Result: null,
483483
StoredException: FatalWorkflowException.CreateNonGeneric(flowId, e.Exception).ToStoredException(),

Core/Cleipnir.ResilientFunctions/Domain/InitialState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ public static InitialState CreateWithMessagesOnly(IEnumerable<MessageAndIdempote
1313
=> new(messages, Effects: []);
1414
}
1515

16-
public record InitialEffect(int Id, object? Value = null, Exception? Exception = null, WorkStatus? Status = null, string? Alias = null);
16+
public record InitialEffect(EffectId Id, object? Value = null, Exception? Exception = null, WorkStatus? Status = null, string? Alias = null);

Stores/StressTests/StressTests/RestartSuspensionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ await registration.Run(
4040
instance,
4141
new InitialState(
4242
[new MessageAndIdempotencyKey("Hello")],
43-
[new InitialEffect(0, Guid.NewGuid())]
43+
[new InitialEffect(0.ToEffectId(), Guid.NewGuid())]
4444
)
4545
);
4646

0 commit comments

Comments
 (0)