Skip to content

Commit bf404be

Browse files
authored
Fix null parent instance details (#137)
1 parent 8a326f1 commit bf404be

File tree

2 files changed

+108
-1
lines changed

2 files changed

+108
-1
lines changed

src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public TaskOrchestrationContextWrapper(
4848
public override string InstanceId => this.innerContext.OrchestrationInstance.InstanceId;
4949

5050
/// <inheritdoc/>
51-
public override ParentOrchestrationInstance? Parent { get; }
51+
public override ParentOrchestrationInstance? Parent => this.invocationContext.Parent;
5252

5353
/// <inheritdoc/>
5454
public override bool IsReplaying => this.innerContext.IsReplaying;
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using DurableTask.Core;
5+
using Microsoft.Extensions.Logging.Abstractions;
6+
7+
namespace Microsoft.DurableTask.Worker.Shims;
8+
9+
public class TaskOrchestrationContextWrapperTests
10+
{
11+
[Fact]
12+
public void Ctor_NullParent_Populates()
13+
{
14+
TestOrchestrationContext innerContext = new();
15+
OrchestrationInvocationContext invocationContext = new("Test", new(), NullLoggerFactory.Instance, null);
16+
string input = "test-input";
17+
18+
TaskOrchestrationContextWrapper wrapper = new(innerContext, invocationContext, input);
19+
20+
VerifyWrapper(wrapper, innerContext, invocationContext, input);
21+
}
22+
23+
[Fact]
24+
public void Ctor_NonNullParent_Populates()
25+
{
26+
TestOrchestrationContext innerContext = new();
27+
ParentOrchestrationInstance parent = new("Parent", Guid.NewGuid().ToString());
28+
OrchestrationInvocationContext invocationContext = new("Test", new(), NullLoggerFactory.Instance, parent);
29+
string input = "test-input";
30+
31+
TaskOrchestrationContextWrapper wrapper = new(innerContext, invocationContext, input);
32+
33+
VerifyWrapper(wrapper, innerContext, invocationContext, input);
34+
}
35+
36+
static void VerifyWrapper<T>(
37+
TaskOrchestrationContextWrapper wrapper,
38+
OrchestrationContext innerContext,
39+
OrchestrationInvocationContext invocationContext,
40+
T input)
41+
{
42+
wrapper.Name.Should().Be(invocationContext.Name);
43+
wrapper.InstanceId.Should().Be(innerContext.OrchestrationInstance.InstanceId);
44+
wrapper.Parent.Should().Be(invocationContext.Parent);
45+
wrapper.IsReplaying.Should().Be(false);
46+
wrapper.GetInput<T>().Should().Be(input);
47+
}
48+
49+
class TestOrchestrationContext : OrchestrationContext
50+
{
51+
public TestOrchestrationContext()
52+
{
53+
this.OrchestrationInstance = new()
54+
{
55+
InstanceId = Guid.NewGuid().ToString(),
56+
ExecutionId = Guid.NewGuid().ToString(),
57+
};
58+
}
59+
60+
public override void ContinueAsNew(object input)
61+
{
62+
throw new NotImplementedException();
63+
}
64+
65+
public override void ContinueAsNew(string newVersion, object input)
66+
{
67+
throw new NotImplementedException();
68+
}
69+
70+
public override Task<T> CreateSubOrchestrationInstance<T>(string name, string version, object input)
71+
{
72+
throw new NotImplementedException();
73+
}
74+
75+
public override Task<T> CreateSubOrchestrationInstance<T>(
76+
string name, string version, string instanceId, object input)
77+
{
78+
throw new NotImplementedException();
79+
}
80+
81+
public override Task<T> CreateSubOrchestrationInstance<T>(
82+
string name, string version, string instanceId, object input, IDictionary<string, string> tags)
83+
{
84+
throw new NotImplementedException();
85+
}
86+
87+
public override Task<T> CreateTimer<T>(DateTime fireAt, T state)
88+
{
89+
throw new NotImplementedException();
90+
}
91+
92+
public override Task<T> CreateTimer<T>(DateTime fireAt, T state, CancellationToken cancelToken)
93+
{
94+
throw new NotImplementedException();
95+
}
96+
97+
public override Task<TResult> ScheduleTask<TResult>(string name, string version, params object[] parameters)
98+
{
99+
throw new NotImplementedException();
100+
}
101+
102+
public override void SendEvent(OrchestrationInstance orchestrationInstance, string eventName, object eventData)
103+
{
104+
throw new NotImplementedException();
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)