Skip to content

Commit ed772d2

Browse files
committed
fixup
1 parent 5af15d0 commit ed772d2

File tree

5 files changed

+70
-54
lines changed

5 files changed

+70
-54
lines changed

src/SignalR/clients/ts/signalr-protocol-msgpack/src/MessagePackHubProtocol.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,28 @@ export class MessagePackHubProtocol implements IHubProtocol {
220220

221221
private writeInvocation(invocationMessage: InvocationMessage): ArrayBuffer {
222222
const msgpack = msgpack5();
223-
const payload = msgpack.encode([MessageType.Invocation, invocationMessage.headers || {}, invocationMessage.invocationId || null,
224-
invocationMessage.target, invocationMessage.arguments, invocationMessage.streamIds]);
223+
let payload: any;
224+
if (invocationMessage.streamIds) {
225+
payload = msgpack.encode([MessageType.Invocation, invocationMessage.headers || {}, invocationMessage.invocationId || null,
226+
invocationMessage.target, invocationMessage.arguments, invocationMessage.streamIds]);
227+
} else {
228+
payload = msgpack.encode([MessageType.Invocation, invocationMessage.headers || {}, invocationMessage.invocationId || null,
229+
invocationMessage.target, invocationMessage.arguments]);
230+
}
225231

226232
return BinaryMessageFormat.write(payload.slice());
227233
}
228234

229235
private writeStreamInvocation(streamInvocationMessage: StreamInvocationMessage): ArrayBuffer {
230236
const msgpack = msgpack5();
231-
const payload = msgpack.encode([MessageType.StreamInvocation, streamInvocationMessage.headers || {}, streamInvocationMessage.invocationId,
232-
streamInvocationMessage.target, streamInvocationMessage.arguments, streamInvocationMessage.streamIds]);
237+
let payload: any;
238+
if (streamInvocationMessage.streamIds) {
239+
payload = msgpack.encode([MessageType.StreamInvocation, streamInvocationMessage.headers || {}, streamInvocationMessage.invocationId,
240+
streamInvocationMessage.target, streamInvocationMessage.arguments, streamInvocationMessage.streamIds]);
241+
} else {
242+
payload = msgpack.encode([MessageType.StreamInvocation, streamInvocationMessage.headers || {}, streamInvocationMessage.invocationId,
243+
streamInvocationMessage.target, streamInvocationMessage.arguments]);
244+
}
233245

234246
return BinaryMessageFormat.write(payload.slice());
235247
}

src/SignalR/clients/ts/signalr/tests/MessageSize.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ function createHubConnection(connection: IConnection, logger?: ILogger | null, p
1818
return HubConnection.create(connection, logger || NullLogger.instance, protocol || new JsonHubProtocol());
1919
}
2020

21+
// These tests check that the message size doesn't change without us being aware of it and making a conscious decision to increase the size
22+
2123
describe("Message size", () => {
2224
it("send invocation", async () => {
2325
await VerifyLogger.run(async (logger) => {

src/SignalR/common/SignalR.Common/test/Internal/Protocol/JsonHubProtocolTestsBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ public void ReadCaseInsensitivePropertiesByDefault()
340340

341341
[Theory]
342342
[MemberData(nameof(MessageSizeDataNames))]
343+
// These tests check that the message size doesn't change without us being aware of it and making a conscious decision to increase the size
343344
public void VerifyMessageSize(string testDataName)
344345
{
345346
var testData = MessageSizeData[testDataName];

src/SignalR/common/SignalR.Common/test/Internal/Protocol/MessagePackHubProtocolTestBase.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,57 @@ public void ParserDoesNotConsumePartialData(byte[] payload)
357357
Assert.Null(message);
358358
}
359359

360+
public static IDictionary<string, MessageSizeTestData> MessageSizeData => new[]
361+
{
362+
new MessageSizeTestData("InvocationMessage_WithoutInvocationId", new InvocationMessage("Target", new object[] { 1 }), 15),
363+
new MessageSizeTestData("InvocationMessage_WithInvocationId", new InvocationMessage("1", "Target", new object[] { 1 }), 16),
364+
new MessageSizeTestData("InvocationMessage_WithInvocationIdAndStreamId", new InvocationMessage("1", "Target", new object[] { 1 }, new string[] { "2" }), 18),
365+
366+
new MessageSizeTestData("CloseMessage_Empty", CloseMessage.Empty, 4),
367+
new MessageSizeTestData("CloseMessage_WithError", new CloseMessage("error"), 9),
368+
369+
new MessageSizeTestData("StreamItemMessage_WithNullItem", new StreamItemMessage("1", null), 7),
370+
new MessageSizeTestData("StreamItemMessage_WithItem", new StreamItemMessage("1", 1), 7),
371+
372+
new MessageSizeTestData("CompletionMessage_Empty", CompletionMessage.Empty("1"), 7),
373+
new MessageSizeTestData("CompletionMessage_WithResult", CompletionMessage.WithResult("1", 1), 8),
374+
new MessageSizeTestData("CompletionMessage_WithError", CompletionMessage.WithError("1", "error"), 13),
375+
376+
new MessageSizeTestData("StreamInvocationMessage", new StreamInvocationMessage("1", "target", Array.Empty<object>()), 15),
377+
new MessageSizeTestData("StreamInvocationMessage_WithStreamId", new StreamInvocationMessage("1", "target", Array.Empty<object>(), new [] { "2" }), 17),
378+
379+
new MessageSizeTestData("CancelInvocationMessage", new CancelInvocationMessage("1"), 6),
380+
381+
new MessageSizeTestData("PingMessage", PingMessage.Instance, 3),
382+
}.ToDictionary(t => t.Name);
383+
384+
public static IEnumerable<object[]> MessageSizeDataNames => MessageSizeData.Keys.Select(name => new object[] { name });
385+
386+
[Theory]
387+
[MemberData(nameof(MessageSizeDataNames))]
388+
// These tests check that the message size doesn't change without us being aware of it and making a conscious decision to increase the size
389+
public void VerifyMessageSize(string testDataName)
390+
{
391+
var testData = MessageSizeData[testDataName];
392+
Assert.Equal(testData.Size, Write(testData.Message).Length);
393+
}
394+
395+
public class MessageSizeTestData
396+
{
397+
public string Name { get; }
398+
public HubMessage Message { get; }
399+
public int Size { get; }
400+
401+
public MessageSizeTestData(string name, HubMessage message, int size)
402+
{
403+
Name = name;
404+
Message = message;
405+
Size = size;
406+
}
407+
408+
public override string ToString() => Name;
409+
}
410+
360411
protected byte ArrayBytes(int size)
361412
{
362413
Debug.Assert(size < 16, "Test code doesn't support array sizes greater than 15");

src/SignalR/common/SignalR.Common/test/Internal/Protocol/MessagePackHubProtocolTests.cs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -195,55 +195,5 @@ public void WriteMessages(string testDataName)
195195

196196
TestWriteMessages(testData);
197197
}
198-
199-
public static IDictionary<string, MessageSizeTestData> MessageSizeData => new[]
200-
{
201-
new MessageSizeTestData("InvocationMessage_WithoutInvocationId", new InvocationMessage("Target", new object[] { 1 }), 15),
202-
new MessageSizeTestData("InvocationMessage_WithInvocationId", new InvocationMessage("1", "Target", new object[] { 1 }), 16),
203-
new MessageSizeTestData("InvocationMessage_WithInvocationIdAndStreamId", new InvocationMessage("1", "Target", new object[] { 1 }, new string[] { "2" }), 18),
204-
205-
new MessageSizeTestData("CloseMessage_Empty", CloseMessage.Empty, 4),
206-
new MessageSizeTestData("CloseMessage_WithError", new CloseMessage("error"), 9),
207-
208-
new MessageSizeTestData("StreamItemMessage_WithNullItem", new StreamItemMessage("1", null), 7),
209-
new MessageSizeTestData("StreamItemMessage_WithItem", new StreamItemMessage("1", 1), 7),
210-
211-
new MessageSizeTestData("CompletionMessage_Empty", CompletionMessage.Empty("1"), 7),
212-
new MessageSizeTestData("CompletionMessage_WithResult", CompletionMessage.WithResult("1", 1), 8),
213-
new MessageSizeTestData("CompletionMessage_WithError", CompletionMessage.WithError("1", "error"), 13),
214-
215-
new MessageSizeTestData("StreamInvocationMessage", new StreamInvocationMessage("1", "target", Array.Empty<object>()), 15),
216-
new MessageSizeTestData("StreamInvocationMessage_WithStreamId", new StreamInvocationMessage("1", "target", Array.Empty<object>(), new [] { "2" }), 17),
217-
218-
new MessageSizeTestData("CancelInvocationMessage", new CancelInvocationMessage("1"), 6),
219-
220-
new MessageSizeTestData("PingMessage", PingMessage.Instance, 3),
221-
}.ToDictionary(t => t.Name);
222-
223-
public static IEnumerable<object[]> MessageSizeDataNames => MessageSizeData.Keys.Select(name => new object[] { name });
224-
225-
[Theory]
226-
[MemberData(nameof(MessageSizeDataNames))]
227-
public void VerifyMessageSize(string testDataName)
228-
{
229-
var testData = MessageSizeData[testDataName];
230-
Assert.Equal(testData.Size, Write(testData.Message).Length);
231-
}
232-
233-
public class MessageSizeTestData
234-
{
235-
public string Name { get; }
236-
public HubMessage Message { get; }
237-
public int Size { get; }
238-
239-
public MessageSizeTestData(string name, HubMessage message, int size)
240-
{
241-
Name = name;
242-
Message = message;
243-
Size = size;
244-
}
245-
246-
public override string ToString() => Name;
247-
}
248198
}
249199
}

0 commit comments

Comments
 (0)