-
Notifications
You must be signed in to change notification settings - Fork 10.4k
[TS Client] Test message size #15099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
src/SignalR/clients/ts/signalr/tests/MessageSize.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
import { HubConnection } from "../src/HubConnection"; | ||
import { IConnection } from "../src/IConnection"; | ||
import { IHubProtocol, MessageType } from "../src/IHubProtocol"; | ||
import { ILogger } from "../src/ILogger"; | ||
import { JsonHubProtocol } from "../src/JsonHubProtocol"; | ||
import { NullLogger } from "../src/Loggers"; | ||
import { Subject } from "../src/Subject"; | ||
import { VerifyLogger } from "./Common"; | ||
import { TestConnection } from "./TestConnection"; | ||
import { delayUntil, registerUnhandledRejectionHandler } from "./Utils"; | ||
|
||
registerUnhandledRejectionHandler(); | ||
|
||
function createHubConnection(connection: IConnection, logger?: ILogger | null, protocol?: IHubProtocol | null) { | ||
return HubConnection.create(connection, logger || NullLogger.instance, protocol || new JsonHubProtocol()); | ||
} | ||
|
||
// 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 | ||
|
||
describe("Message size", () => { | ||
it("send invocation", async () => { | ||
await VerifyLogger.run(async (logger) => { | ||
const connection = new TestConnection(); | ||
|
||
const hubConnection = createHubConnection(connection, logger); | ||
try { | ||
// We don't actually care to wait for the send. | ||
// tslint:disable-next-line:no-floating-promises | ||
hubConnection.send("target", 1) | ||
.catch((_) => { }); // Suppress exception and unhandled promise rejection warning. | ||
|
||
// Verify the message is sent | ||
expect(connection.sentData.length).toBe(1); | ||
expect(connection.parsedSentData[0].type).toEqual(MessageType.Invocation); | ||
expect((connection.sentData[0] as string).length).toEqual(44); | ||
} finally { | ||
// Close the connection | ||
await hubConnection.stop(); | ||
} | ||
}); | ||
}); | ||
|
||
it("invoke invocation", async () => { | ||
await VerifyLogger.run(async (logger) => { | ||
const connection = new TestConnection(); | ||
|
||
const hubConnection = createHubConnection(connection, logger); | ||
try { | ||
// We don't actually care to wait for the invoke. | ||
// tslint:disable-next-line:no-floating-promises | ||
hubConnection.invoke("target", 1) | ||
.catch((_) => { }); // Suppress exception and unhandled promise rejection warning. | ||
|
||
// Verify the message is sent | ||
expect(connection.sentData.length).toBe(1); | ||
expect(connection.parsedSentData[0].type).toEqual(MessageType.Invocation); | ||
expect((connection.sentData[0] as string).length).toEqual(63); | ||
} finally { | ||
// Close the connection | ||
await hubConnection.stop(); | ||
} | ||
}); | ||
}); | ||
|
||
it("stream invocation", async () => { | ||
await VerifyLogger.run(async (logger) => { | ||
const connection = new TestConnection(); | ||
|
||
const hubConnection = createHubConnection(connection, logger); | ||
try { | ||
hubConnection.stream("target", 1); | ||
|
||
// Verify the message is sent | ||
expect(connection.sentData.length).toBe(1); | ||
expect(connection.parsedSentData[0].type).toEqual(MessageType.StreamInvocation); | ||
expect((connection.sentData[0] as string).length).toEqual(63); | ||
} finally { | ||
// Close the connection | ||
await hubConnection.stop(); | ||
} | ||
}); | ||
}); | ||
|
||
it("upload invocation", async () => { | ||
await VerifyLogger.run(async (logger) => { | ||
const connection = new TestConnection(); | ||
|
||
const hubConnection = createHubConnection(connection, logger); | ||
try { | ||
// We don't actually care to wait for the invoke. | ||
// tslint:disable-next-line:no-floating-promises | ||
hubConnection.invoke("target", 1, new Subject()) | ||
.catch((_) => { }); // Suppress exception and unhandled promise rejection warning. | ||
|
||
// Verify the message is sent | ||
expect(connection.sentData.length).toBe(1); | ||
expect(connection.parsedSentData[0].type).toEqual(MessageType.Invocation); | ||
expect((connection.sentData[0] as string).length).toEqual(81); | ||
} finally { | ||
// Close the connection | ||
await hubConnection.stop(); | ||
} | ||
}); | ||
}); | ||
|
||
it("upload stream invocation", async () => { | ||
await VerifyLogger.run(async (logger) => { | ||
const connection = new TestConnection(); | ||
|
||
const hubConnection = createHubConnection(connection, logger); | ||
try { | ||
hubConnection.stream("target", 1, new Subject()); | ||
|
||
// Verify the message is sent | ||
expect(connection.sentData.length).toBe(1); | ||
expect(connection.parsedSentData[0].type).toEqual(MessageType.StreamInvocation); | ||
expect((connection.sentData[0] as string).length).toEqual(81); | ||
} finally { | ||
// Close the connection | ||
await hubConnection.stop(); | ||
} | ||
}); | ||
}); | ||
|
||
it("completion message", async () => { | ||
await VerifyLogger.run(async (logger) => { | ||
const connection = new TestConnection(); | ||
|
||
const hubConnection = createHubConnection(connection, logger); | ||
try { | ||
const subject = new Subject(); | ||
hubConnection.stream("target", 1, subject); | ||
subject.complete(); | ||
|
||
await delayUntil(1000, () => connection.sentData.length === 2); | ||
|
||
// Verify the message is sent | ||
expect(connection.sentData.length).toBe(2); | ||
expect(connection.parsedSentData[1].type).toEqual(MessageType.Completion); | ||
expect((connection.sentData[1] as string).length).toEqual(29); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we verify the message type is what we expect before verifying the length? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} finally { | ||
// Close the connection | ||
await hubConnection.stop(); | ||
} | ||
}); | ||
}); | ||
|
||
it("cancel message", async () => { | ||
await VerifyLogger.run(async (logger) => { | ||
const connection = new TestConnection(); | ||
|
||
const hubConnection = createHubConnection(connection, logger); | ||
try { | ||
hubConnection.stream("target", 1).subscribe({ | ||
complete: () => {}, | ||
error: () => {}, | ||
next: () => {}, | ||
}).dispose(); | ||
|
||
await delayUntil(1000, () => connection.sentData.length === 2); | ||
|
||
// Verify the message is sent | ||
expect(connection.sentData.length).toBe(2); | ||
expect(connection.parsedSentData[1].type).toEqual(MessageType.CancelInvocation); | ||
expect((connection.sentData[1] as string).length).toEqual(29); | ||
} finally { | ||
// Close the connection | ||
await hubConnection.stop(); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the TS tests for MessagePack? It looks like these are only testing JsonHubProtocol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No tests for MessagePack, that's what we were talking about Friday when we decided to just get the PR in.