fix(worker): send the Write2/WriteSecured2 time argument as box-local time (#228)
MXAccess reads the VT_DATE time argument of Write2, WriteSecured2 and their bulk forms as box-local time and converts it to UTC itself. The worker passed the proto Timestamp's UTC clock fields (the COM marshaler ignores DateTime.Kind), so on vd03 (UTC-5) a Write2 sent at 01:33:00Z was stored at 06:33:00Z. VariantConverter.ConvertToComTimestamp converts a timestamp_value instant with TimeZoneInfo.ConvertTimeFromUtc into the worker's zone (TimeZoneInfo.Local by default, DST included; an injectable zone for tests). The executor uses it for the time argument only: value conversion is unchanged, and the read direction (MXAccess reports UTC; ToTimestamp treats it as UTC) is unchanged. The one residual loss is MXAccess-side: the repeated fall-back hour cannot be told apart in an offset-less VT_DATE. Tests: VariantConverterTimestampTests (UTC-5, US-Eastern DST both edges, UTC+05:30, UTC, fall-back ambiguity, value path unchanged); the four executor forwarding tests inject a fixed UTC-5 zone; the windev live Write2 smoke now sends a past whole-second timestamp and asserts the stored one when applied. Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
@@ -319,11 +319,21 @@ public sealed class WorkerLiveMxAccessSmokeTests(ITestOutputHelper output)
|
||||
LogEvent(initialValue);
|
||||
originalValue = initialValue.Value;
|
||||
|
||||
// A whole-second instant 30 s in the past, so a stored source timestamp
|
||||
// can be compared exactly and cannot be confused with the write time.
|
||||
DateTime sentTimestampUtc = DateTime.UtcNow.AddSeconds(-30);
|
||||
sentTimestampUtc = new DateTime(
|
||||
sentTimestampUtc.Ticks - (sentTimestampUtc.Ticks % TimeSpan.TicksPerSecond),
|
||||
DateTimeKind.Utc);
|
||||
output.WriteLine(
|
||||
$"Write2 timestamp sent={sentTimestampUtc:O} box zone={TimeZoneInfo.Local.Id} offset={TimeZoneInfo.Local.GetUtcOffset(sentTimestampUtc)}");
|
||||
|
||||
MxCommandReply writeReply = await fixture.Service.Invoke(
|
||||
CreateWrite2Request(
|
||||
sessionId,
|
||||
registerReply.Register.ServerHandle,
|
||||
addItemReply.AddItem.ItemHandle),
|
||||
addItemReply.AddItem.ItemHandle,
|
||||
sentTimestampUtc),
|
||||
new TestServerCallContext()).ConfigureAwait(false);
|
||||
LogReply("Write2", writeReply);
|
||||
|
||||
@@ -362,6 +372,34 @@ public sealed class WorkerLiveMxAccessSmokeTests(ITestOutputHelper output)
|
||||
output.WriteLine($"Write2 completion category={status.Category} detail={status.Detail}");
|
||||
}
|
||||
|
||||
// #228: MXAccess reads the Write2 time argument as box-local time, so
|
||||
// the worker must convert the UTC instant before the COM call. When the
|
||||
// provider applied the write, the source timestamp it reports must be
|
||||
// the instant sent. On a UTC box this cannot fail either way, so the
|
||||
// zone is logged above. A refused write (no data change) is logged,
|
||||
// not asserted, as before.
|
||||
bool applied = writeComplete.Statuses.Count > 0
|
||||
&& writeComplete.Statuses.All(status => status.Category == MxStatusCategory.Ok);
|
||||
if (applied)
|
||||
{
|
||||
MxEvent writtenValue = await eventWriter
|
||||
.WaitForMessageAsync(
|
||||
candidate => candidate.Family == MxEventFamily.OnDataChange
|
||||
&& candidate.ItemHandle == addItemReply.AddItem.ItemHandle
|
||||
&& candidate.WorkerSequence > initialValue.WorkerSequence,
|
||||
IntegrationTestEnvironment.LiveMxAccessEventTimeout,
|
||||
streamCancellation.Token)
|
||||
.ConfigureAwait(false);
|
||||
LogEvent(writtenValue);
|
||||
DateTime? storedTimestampUtc = writtenValue.SourceTimestamp?.ToDateTime();
|
||||
output.WriteLine($"Write2 timestamp stored={storedTimestampUtc:O}");
|
||||
Assert.Equal(sentTimestampUtc, storedTimestampUtc);
|
||||
}
|
||||
else
|
||||
{
|
||||
output.WriteLine("Write2 timestamp not checked: the completion was not Ok, so nothing was applied.");
|
||||
}
|
||||
|
||||
// Restore the original value with a plain Write on the same supervisory advise.
|
||||
MxCommandReply restoreReply = await fixture.Service.Invoke(
|
||||
CreateWriteRequest(
|
||||
@@ -1666,7 +1704,8 @@ public sealed class WorkerLiveMxAccessSmokeTests(ITestOutputHelper output)
|
||||
private static MxCommandRequest CreateWrite2Request(
|
||||
string sessionId,
|
||||
int serverHandle,
|
||||
int itemHandle)
|
||||
int itemHandle,
|
||||
DateTime timestampUtc)
|
||||
{
|
||||
return new MxCommandRequest
|
||||
{
|
||||
@@ -1688,7 +1727,7 @@ public sealed class WorkerLiveMxAccessSmokeTests(ITestOutputHelper output)
|
||||
{
|
||||
DataType = MxDataType.Time,
|
||||
VariantType = "VT_DATE",
|
||||
TimestampValue = Timestamp.FromDateTime(DateTime.UtcNow),
|
||||
TimestampValue = Timestamp.FromDateTime(timestampUtc),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user