Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/DurableTask.SqlServer/SqlOrchestrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public override async Task CompleteTaskOrchestrationWorkItemAsync(
command.Parameters.Add("@InstanceID", SqlDbType.VarChar, size: 100).Value = instance.InstanceId;
command.Parameters.Add("@ExecutionID", SqlDbType.VarChar, size: 50).Value = instance.ExecutionId;
command.Parameters.Add("@RuntimeStatus", SqlDbType.VarChar, size: 30).Value = orchestrationState.OrchestrationStatus.ToString();
command.Parameters.Add("@CustomStatusPayload", SqlDbType.VarChar).Value = orchestrationState.Status ?? SqlString.Null;
command.Parameters.Add("@CustomStatusPayload", SqlDbType.VarChar, size: -1 /* max */).Value = orchestrationState.Status ?? SqlString.Null;

bool hasSession = workItem.Session != null;
bool keepLocked = hasSession && !IsTerminalStatus(orchestrationState.OrchestrationStatus);
Expand Down Expand Up @@ -666,15 +666,15 @@ public override async Task CreateTaskOrchestrationAsync(TaskMessage creationMess
command.Parameters.Add("@Version", SqlDbType.VarChar, size: 100).Value = startEvent.Version;
command.Parameters.Add("@InstanceID", SqlDbType.VarChar, size: 100).Value = instance.InstanceId;
command.Parameters.Add("@ExecutionID", SqlDbType.VarChar, size: 50).Value = instance.ExecutionId;
command.Parameters.Add("@InputText", SqlDbType.VarChar).Value = startEvent.Input;
command.Parameters.Add("@InputText", SqlDbType.VarChar, size: -1 /* max */).Value = startEvent.Input;
command.Parameters.Add("@StartTime", SqlDbType.DateTime2).Value = startEvent.ScheduledStartTime;
command.Parameters.Add("@TraceContext", SqlDbType.VarChar, size: 800).Value = SqlUtils.GetTraceContext(startEvent);

command.Parameters.AddTagsParameter(startEvent.Tags);

if (dedupeStatuses?.Length > 0)
{
command.Parameters.Add("@DedupeStatuses", SqlDbType.VarChar).Value = string.Join(",", dedupeStatuses);
command.Parameters.Add("@DedupeStatuses", SqlDbType.VarChar, size: -1 /* max */).Value = string.Join(",", dedupeStatuses);
}

try
Expand Down Expand Up @@ -812,7 +812,7 @@ public override async Task ForceTerminateTaskOrchestrationAsync(string instanceI
using SqlCommand command = this.GetSprocCommand(connection, $"{this.settings.SchemaName}.TerminateInstance");

command.Parameters.Add("@InstanceID", SqlDbType.VarChar, size: 100).Value = instanceId;
command.Parameters.Add("@Reason", SqlDbType.VarChar).Value = reason;
command.Parameters.Add("@Reason", SqlDbType.VarChar, size: -1 /* max */).Value = reason;

await SqlUtils.ExecuteNonQueryAsync(command, this.traceHelper, instanceId);
}
Expand Down Expand Up @@ -1011,7 +1011,7 @@ public async Task RewindTaskOrchestrationAsync(string instanceId, string reason)
using SqlCommand command = this.GetSprocCommand(connection, $"{this.settings.SchemaName}._RewindInstance");

command.Parameters.Add("@InstanceID", SqlDbType.VarChar, size: 100).Value = instanceId;
command.Parameters.Add("@Reason", SqlDbType.VarChar).Value = reason;
command.Parameters.Add("@Reason", SqlDbType.VarChar, size: -1 /* max */).Value = reason;

await SqlUtils.ExecuteNonQueryAsync(command, this.traceHelper);
}
Expand Down
98 changes: 98 additions & 0 deletions test/DurableTask.SqlServer.Tests/Integration/Orchestrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,104 @@ public async Task Termination()
LogAssert.CheckpointCompleted(orchestrationName));
}

// Each 'あ' is 3 bytes in UTF-8, so this string is under 8,000 characters but over 8,000 bytes.
// Regression coverage for https://github.com/microsoft/durabletask-mssql/issues/333.
static readonly string LargeUtf8Payload = new string('あ', 3000);

[Fact]
public async Task LargeUtf8Input()
{
TestInstance<string> instance = await this.testService.RunOrchestration(
LargeUtf8Payload,
orchestrationName: "EchoOrchestration",
implementation: (ctx, input) => Task.FromResult(input));

await instance.WaitForCompletion(expectedOutput: LargeUtf8Payload);
}

[Fact]
public async Task LargeUtf8CustomStatus()
{
// Keep the input small so this test exercises only the custom status parameter.
TestInstance<string> instance = await this.testService.RunOrchestration(
"input",
orchestrationName: "CustomStatusOrchestration",
new LargeCustomStatusOrchestration());

OrchestrationState state = await instance.WaitForCompletion(expectedOutput: "done");
Assert.Equal(LargeUtf8Payload, JToken.Parse(state.Status).ToString());
}

class LargeCustomStatusOrchestration : TaskOrchestration<string, string>
{
string status;

public override Task<string> RunTask(OrchestrationContext context, string input)
{
this.status = LargeUtf8Payload;
return Task.FromResult("done");
}

public override string OnGetStatus() => this.status;
}

[Fact]
public async Task LargeUtf8TerminateReason()
{
TestInstance<string> instance = await this.testService.RunOrchestration(
"input",
orchestrationName: "OrchestrationWithTimer",
implementation: (ctx, input) => ctx.CreateTimer(ctx.CurrentUtcDateTime.AddSeconds(30), input));

await instance.WaitForStart();
await instance.TerminateAsync(LargeUtf8Payload);

await instance.WaitForCompletion(
TimeSpan.FromSeconds(10),
expectedStatus: OrchestrationStatus.Terminated,
expectedOutput: LargeUtf8Payload);
}

[Fact]
public async Task LargeUtf8RewindReason()
{
bool shouldFail = true;

TestInstance<string> instance = await this.testService.RunOrchestration(
"input",
orchestrationName: "RewindableOrchestration",
implementation: (ctx, input) => ctx.ScheduleTask<string>("MaybeFail", "", input),
activities: ("MaybeFail", TestService.MakeActivity((TaskContext ctx, string input) =>
{
if (shouldFail)
{
throw new InvalidOperationException("Kah-BOOOOM!!!");
}

return input;
})));

await instance.WaitForCompletion(expectedStatus: OrchestrationStatus.Failed);

shouldFail = false;
await this.testService.OrchestrationServiceMock.Object.RewindTaskOrchestrationAsync(
instance.InstanceId,
LargeUtf8Payload);

await instance.WaitForCompletion(expectedOutput: "input");
Comment thread
sophiatev marked this conversation as resolved.
Resolved

// The rewind reason is persisted as the payload of a GenericEvent in the orchestration history.
// Rewind also converts the failure-related events into GenericEvents (with their original
// payloads), so look for the one carrying the reason rather than for a single GenericEvent.
string historyJson = await this.testService.OrchestrationServiceMock.Object.GetOrchestrationHistoryAsync(
instance.InstanceId,
executionIdFilter: null);
Assert.Single(
JArray.Parse(historyJson),
e => e.Value<int>("EventType") == (int)EventType.GenericEvent
&& e.Value<string>("Data") == LargeUtf8Payload);
}

[Theory]
[InlineData(10)]
[InlineData(300)]
Expand Down
22 changes: 22 additions & 0 deletions test/DurableTask.SqlServer.Tests/Utils/TestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,28 @@ public async Task<TestInstance<TInput>> RunOrchestrationWithTags<TOutput, TInput
input);
}

// Runs a caller-supplied orchestration object, for tests that need to override TaskOrchestration
// members (e.g. OnGetStatus) that the inline implementation delegates can't reach.
public async Task<TestInstance<TInput>> RunOrchestration<TInput>(
TInput input,
string orchestrationName,
TaskOrchestration orchestration)
{
this.worker.AddTaskOrchestrations(new TestObjectCreator<TaskOrchestration>(
orchestrationName,
string.Empty,
orchestration));

DateTime utcNow = DateTime.UtcNow;
OrchestrationInstance instance = await this.client.CreateOrchestrationInstanceAsync(
orchestrationName,
string.Empty,
Guid.NewGuid().ToString("N"),
input);

return new TestInstance<TInput>(this.client, instance, orchestrationName, string.Empty, utcNow, input);
}

public void RegisterInlineActivity(string name, string version, TaskActivity activity)
{
this.worker.AddTaskActivities(new TestObjectCreator<TaskActivity>(name, version, activity));
Expand Down
Loading