Skip to content

Commit 87d06d3

Browse files
committed
fixup
1 parent f727a32 commit 87d06d3

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
@@ -221,16 +221,28 @@ export class MessagePackHubProtocol implements IHubProtocol {
221221

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

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

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

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

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
@@ -342,6 +342,7 @@ public void ReadCaseInsensitivePropertiesByDefault()
342342

343343
[Theory]
344344
[MemberData(nameof(MessageSizeDataNames))]
345+
// 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
345346
public void VerifyMessageSize(string testDataName)
346347
{
347348
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
@@ -375,6 +375,57 @@ public void ParserDoesNotConsumePartialData(byte[] payload)
375375
Assert.Null(message);
376376
}
377377

378+
public static IDictionary<string, MessageSizeTestData> MessageSizeData => new[]
379+
{
380+
new MessageSizeTestData("InvocationMessage_WithoutInvocationId", new InvocationMessage("Target", new object[] { 1 }), 15),
381+
new MessageSizeTestData("InvocationMessage_WithInvocationId", new InvocationMessage("1", "Target", new object[] { 1 }), 16),
382+
new MessageSizeTestData("InvocationMessage_WithInvocationIdAndStreamId", new InvocationMessage("1", "Target", new object[] { 1 }, new string[] { "2" }), 18),
383+
384+
new MessageSizeTestData("CloseMessage_Empty", CloseMessage.Empty, 4),
385+
new MessageSizeTestData("CloseMessage_WithError", new CloseMessage("error"), 9),
386+
387+
new MessageSizeTestData("StreamItemMessage_WithNullItem", new StreamItemMessage("1", null), 7),
388+
new MessageSizeTestData("StreamItemMessage_WithItem", new StreamItemMessage("1", 1), 7),
389+
390+
new MessageSizeTestData("CompletionMessage_Empty", CompletionMessage.Empty("1"), 7),
391+
new MessageSizeTestData("CompletionMessage_WithResult", CompletionMessage.WithResult("1", 1), 8),
392+
new MessageSizeTestData("CompletionMessage_WithError", CompletionMessage.WithError("1", "error"), 13),
393+
394+
new MessageSizeTestData("StreamInvocationMessage", new StreamInvocationMessage("1", "target", Array.Empty<object>()), 15),
395+
new MessageSizeTestData("StreamInvocationMessage_WithStreamId", new StreamInvocationMessage("1", "target", Array.Empty<object>(), new [] { "2" }), 17),
396+
397+
new MessageSizeTestData("CancelInvocationMessage", new CancelInvocationMessage("1"), 6),
398+
399+
new MessageSizeTestData("PingMessage", PingMessage.Instance, 3),
400+
}.ToDictionary(t => t.Name);
401+
402+
public static IEnumerable<object[]> MessageSizeDataNames => MessageSizeData.Keys.Select(name => new object[] { name });
403+
404+
[Theory]
405+
[MemberData(nameof(MessageSizeDataNames))]
406+
// 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
407+
public void VerifyMessageSize(string testDataName)
408+
{
409+
var testData = MessageSizeData[testDataName];
410+
Assert.Equal(testData.Size, Write(testData.Message).Length);
411+
}
412+
413+
public class MessageSizeTestData
414+
{
415+
public string Name { get; }
416+
public HubMessage Message { get; }
417+
public int Size { get; }
418+
419+
public MessageSizeTestData(string name, HubMessage message, int size)
420+
{
421+
Name = name;
422+
Message = message;
423+
Size = size;
424+
}
425+
426+
public override string ToString() => Name;
427+
}
428+
378429
protected byte ArrayBytes(int size)
379430
{
380431
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
@@ -203,55 +203,5 @@ public void WriteMessages(string testDataName)
203203

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

0 commit comments

Comments
 (0)