Родитель
202ebf0934
Коммит
045c5ea0bc
|
@ -12,7 +12,7 @@ COPY server ./
|
|||
RUN dotnet publish -c Release -o out
|
||||
|
||||
# build runtime image
|
||||
FROM zackliu/signalr-test-base
|
||||
FROM signalr-test-base
|
||||
|
||||
ENV Azure__SignalR__ConnectionString="" \
|
||||
DELAY="500" \
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# build runtime image
|
||||
FROM ubuntu:16.04
|
||||
FROM ubuntu:18.04
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
wget \
|
||||
|
@ -17,7 +17,7 @@ RUN apt-get update -y \
|
|||
&& apt-get install -y aspnetcore-runtime-2.1
|
||||
|
||||
# Install Node.js
|
||||
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - \
|
||||
RUN curl -sL https://deb.nodesource.com/setup_lts.x | bash - \
|
||||
&& apt-get install -y nodejs \
|
||||
&& apt-get install -y build-essential \
|
||||
&& npm install -g npm
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
# .npmrc
|
||||
engine-strict=true
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -2,7 +2,7 @@
|
|||
"name": "azure-signalr-test",
|
||||
"version": "0.1.0",
|
||||
"scripts": {
|
||||
"test": "jest -w 1"
|
||||
"test": "jest -w 1 --forceExit"
|
||||
},
|
||||
"jest": {
|
||||
"testEnvironment": "node",
|
||||
|
@ -24,6 +24,10 @@
|
|||
"jest-junit"
|
||||
]
|
||||
},
|
||||
"engines": {
|
||||
"npm" : ">=8.0.0 <9.0.0",
|
||||
"node" : ">=16.0.0 <17.0.0"
|
||||
},
|
||||
"jest-junit": {
|
||||
"suiteName": "jest tests",
|
||||
"outputDirectory": ".",
|
||||
|
@ -39,7 +43,7 @@
|
|||
"jest": "^23.5.0",
|
||||
"jest-junit": "^5.2.0",
|
||||
"njwt": "^0.4.0",
|
||||
"npm": "^6.14.14",
|
||||
"npm": "^8.0.0",
|
||||
"request": "^2.88.0",
|
||||
"request-promise": "^4.2.2",
|
||||
"semver": "^5.5.1",
|
||||
|
|
|
@ -1,21 +1,35 @@
|
|||
import { delay, getConnections, startConnections, stopConnections } from "./utils";
|
||||
import {
|
||||
delay,
|
||||
getConnections,
|
||||
startConnections,
|
||||
stopConnections,
|
||||
} from "./utils";
|
||||
import { Constant } from "./constant";
|
||||
import * as request from "request-promise";
|
||||
|
||||
const testMessage = 'Test Message';
|
||||
const testMessage = "Test Message";
|
||||
|
||||
test('auth with jwt', async () => {
|
||||
let usernameFactory = function (_): string { return 'jwtUser' };
|
||||
test("auth with jwt", async () => {
|
||||
let usernameFactory = function (_): string {
|
||||
return "jwtUser";
|
||||
};
|
||||
let username = usernameFactory(0);
|
||||
let role = 'Admin';
|
||||
let token = await request(`${Constant.Server.Host}/jwt/login?username=${username}&role=${role}`);
|
||||
let role = "Admin";
|
||||
let token = await request(
|
||||
`${Constant.Server.Host}/jwt/login?username=${username}&role=${role}`
|
||||
);
|
||||
|
||||
let connections = getConnections(1, Constant.Server.ChatJwtUrl, usernameFactory, () => token);
|
||||
let connections = getConnections(
|
||||
1,
|
||||
Constant.Server.ChatJwtUrl,
|
||||
usernameFactory,
|
||||
() => token
|
||||
);
|
||||
let callback = jest.fn();
|
||||
connections[0].on(Constant.echo, callback);
|
||||
await startConnections(connections);
|
||||
await connections[0].invoke(Constant.echo, 'connection0', testMessage);
|
||||
await connections[0].invoke(Constant.echo, "connection0", testMessage);
|
||||
await delay(Constant.delay);
|
||||
expect(callback).toHaveBeenCalledWith('connection0', testMessage);
|
||||
expect(callback).toHaveBeenCalledWith("connection0", testMessage);
|
||||
await stopConnections(connections);
|
||||
});
|
|
@ -1,17 +1,23 @@
|
|||
import { DeferMap, getConnections, promiseOrTimeout, startConnections, stopConnections } from "./utils";
|
||||
import {
|
||||
DeferMap,
|
||||
getConnections,
|
||||
promiseOrTimeout,
|
||||
startConnections,
|
||||
stopConnections,
|
||||
} from "./utils";
|
||||
import { Constant } from "./constant";
|
||||
|
||||
const testMessage = 'Test Message';
|
||||
const testMessage = "Test Message";
|
||||
|
||||
test('connect to server', async () => {
|
||||
test("connect to server", async () => {
|
||||
const connections = getConnections(1);
|
||||
await startConnections(connections);
|
||||
await stopConnections(connections);
|
||||
});
|
||||
|
||||
test('echo', async () => {
|
||||
test("echo", async () => {
|
||||
const connections = getConnections(1);
|
||||
const connectionName = 'connection';
|
||||
const connectionName = "connection";
|
||||
|
||||
const echoCallback = jest.fn();
|
||||
connections[0].on(Constant.echo, echoCallback);
|
||||
|
@ -24,7 +30,7 @@ test('echo', async () => {
|
|||
await stopConnections(connections);
|
||||
});
|
||||
|
||||
test('broadcast', async () => {
|
||||
test("broadcast", async () => {
|
||||
const deferMap = new DeferMap();
|
||||
|
||||
let connections = getConnections(3);
|
||||
|
@ -35,11 +41,11 @@ test('broadcast', async () => {
|
|||
|
||||
let promise = deferMap.waitForPromise(3);
|
||||
await connections[0].invoke(Constant.broadcast, "connection0", testMessage);
|
||||
expect(await promise).toEqual(['connection0', testMessage]);
|
||||
expect(await promise).toEqual(["connection0", testMessage]);
|
||||
await stopConnections(connections);
|
||||
});
|
||||
|
||||
test('send others', async () => {
|
||||
test("send others", async () => {
|
||||
const deferMapList = [new DeferMap(), new DeferMap(), new DeferMap()];
|
||||
|
||||
let connections = getConnections(3);
|
||||
|
@ -52,9 +58,11 @@ test('send others', async () => {
|
|||
let promise1 = deferMapList[1].waitForPromise(1);
|
||||
let promise2 = deferMapList[2].waitForPromise(1);
|
||||
await connections[0].invoke(Constant.sendOthers, "connection0", testMessage);
|
||||
expect(await promise1).toEqual(['connection0', testMessage]);
|
||||
expect(await promise2).toEqual(['connection0', testMessage]);
|
||||
await promiseOrTimeout(promise0, Constant.awaitTimeout).catch(error => expect(error).not.toBeNull());
|
||||
expect(await promise1).toEqual(["connection0", testMessage]);
|
||||
expect(await promise2).toEqual(["connection0", testMessage]);
|
||||
await promiseOrTimeout(promise0, Constant.awaitTimeout).catch((error) =>
|
||||
expect(error).not.toBeNull()
|
||||
);
|
||||
|
||||
await stopConnections(connections);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
export class Constant {
|
||||
public static readonly broadcast = 'broadcast';
|
||||
public static readonly echo = 'echo';
|
||||
public static readonly sendOthers = 'sendothers';
|
||||
public static readonly joinGroup = 'joingroup';
|
||||
public static readonly leaveGroup = 'leavegroup';
|
||||
public static readonly sendGroup = 'sendgroup';
|
||||
public static readonly sendGroups = 'sendgroups';
|
||||
public static readonly sendGroupExcept = 'sendgroupexcept';
|
||||
public static readonly sendOthersInGroup = 'sendothersingroup';
|
||||
public static readonly sendUser = 'senduser';
|
||||
public static readonly sendUsers = 'sendusers';
|
||||
public static readonly getConnectionId = 'getconnectionid';
|
||||
public static readonly broadcast = "broadcast";
|
||||
public static readonly echo = "echo";
|
||||
public static readonly sendOthers = "sendothers";
|
||||
public static readonly joinGroup = "joingroup";
|
||||
public static readonly leaveGroup = "leavegroup";
|
||||
public static readonly sendGroup = "sendgroup";
|
||||
public static readonly sendGroups = "sendgroups";
|
||||
public static readonly sendGroupExcept = "sendgroupexcept";
|
||||
public static readonly sendOthersInGroup = "sendothersingroup";
|
||||
public static readonly sendUser = "senduser";
|
||||
public static readonly sendUsers = "sendusers";
|
||||
public static readonly getConnectionId = "getconnectionid";
|
||||
|
||||
public static readonly port = parseInt(process.env.PORT) || 80;
|
||||
|
||||
public static readonly Server = function () {
|
||||
public static readonly Server = (function () {
|
||||
let port = Constant.port;
|
||||
let host = `http://localhost:${port}`;
|
||||
return {
|
||||
|
@ -23,10 +23,12 @@ export class Constant {
|
|||
ChatUrl: `${host}/chat`,
|
||||
ChatJwtUrl: `${host}/chatJwt`,
|
||||
JwtLoginUrl: `${host}/Jwt/login`,
|
||||
}
|
||||
}();
|
||||
};
|
||||
})();
|
||||
|
||||
public static readonly delay = Number(process.env.DELAY || 1000);
|
||||
public static readonly timeout = Number(process.env.TIMEOUT || 60000); // Timeout for each test
|
||||
public static readonly awaitTimeout = Number(process.env.TIMEOUT_AWAIT || 1000); // Timeout for await operation
|
||||
public static readonly awaitTimeout = Number(
|
||||
process.env.TIMEOUT_AWAIT || 1000
|
||||
); // Timeout for await operation
|
||||
}
|
|
@ -1,10 +1,17 @@
|
|||
import { getConnections, startConnections, DeferMap, promiseOrTimeout, stopConnections } from './utils';
|
||||
import {
|
||||
getConnections,
|
||||
startConnections,
|
||||
DeferMap,
|
||||
promiseOrTimeout,
|
||||
stopConnections,
|
||||
} from "./utils";
|
||||
import { Constant } from "./constant";
|
||||
import { disposeEmitNodes } from "typescript";
|
||||
|
||||
test('join and leave group', async () => {
|
||||
test("join and leave group", async () => {
|
||||
const deferMapList = [new DeferMap(), new DeferMap(), new DeferMap()];
|
||||
const groupName = 'Test Group';
|
||||
const testMessage = 'Test Message';
|
||||
const groupName = "Test Group";
|
||||
const testMessage = "Test Message";
|
||||
|
||||
let connections = getConnections(3);
|
||||
connections[0].on(Constant.echo, deferMapList[0].callback());
|
||||
|
@ -13,29 +20,37 @@ test('join and leave group', async () => {
|
|||
await startConnections(connections);
|
||||
|
||||
let promise0 = deferMapList[0].waitForPromise(1);
|
||||
await connections[0].invoke(Constant.joinGroup, 'connection0', groupName)
|
||||
.catch(err => expect(err).toBeNull());
|
||||
expect(await promise0).toEqual(['connection0', groupName]);
|
||||
await connections[0]
|
||||
.invoke(Constant.joinGroup, "connection0", groupName)
|
||||
.catch((err) => expect(err).toBeNull());
|
||||
expect(await promise0).toEqual(["connection0", groupName]);
|
||||
|
||||
promise0 = deferMapList[0].waitForPromise(2);
|
||||
let promise1 = deferMapList[1].waitForPromise(1);
|
||||
let promise2 = deferMapList[2].waitForPromise(1);
|
||||
await connections[1].invoke(Constant.joinGroup, 'connection1', groupName)
|
||||
.catch(err => expect(err).toBeNull());
|
||||
expect(await promise0).toEqual(['connection1', groupName]);
|
||||
expect(await promise1).toEqual(['connection1', groupName]);
|
||||
await connections[1]
|
||||
.invoke(Constant.joinGroup, "connection1", groupName)
|
||||
.catch((err) => expect(err).toBeNull());
|
||||
expect(await promise0).toEqual(["connection1", groupName]);
|
||||
expect(await promise1).toEqual(["connection1", groupName]);
|
||||
await promiseOrTimeout(promise2, Constant.awaitTimeout).catch((error) => {
|
||||
expect(error).not.toBeNull();
|
||||
});
|
||||
|
||||
// Leave group
|
||||
promise1 = deferMapList[1].waitForPromise(2);
|
||||
await connections[1].invoke(Constant.leaveGroup, 'connection1', groupName)
|
||||
.catch(err => expect(err).toBeNull());
|
||||
await connections[1]
|
||||
.invoke(Constant.leaveGroup, "connection1", groupName)
|
||||
.catch((err) => expect(err).toBeNull());
|
||||
await promise1;
|
||||
|
||||
promise1 = deferMapList[1].waitForPromise(3);
|
||||
await connections[0].invoke(Constant.sendGroup, 'connection0', groupName, testMessage);
|
||||
await connections[0].invoke(
|
||||
Constant.sendGroup,
|
||||
"connection0",
|
||||
groupName,
|
||||
testMessage
|
||||
);
|
||||
await promiseOrTimeout(promise1, Constant.awaitTimeout).catch((error) => {
|
||||
expect(error).not.toBeNull();
|
||||
});
|
||||
|
@ -43,60 +58,84 @@ test('join and leave group', async () => {
|
|||
await stopConnections(connections);
|
||||
});
|
||||
|
||||
test('send group / groups / group except', async () => {
|
||||
const connectionIdPromiseName = 'connectionId';
|
||||
test("send group / groups / group except", async () => {
|
||||
const connectionIdPromiseName = "connectionId";
|
||||
const deferMapList = [new DeferMap(), new DeferMap(), new DeferMap()];
|
||||
const groupName = 'Test Group';
|
||||
const groupName2 = 'Test Group 2';
|
||||
const testMessage = 'Test Message';
|
||||
const groupName = "Test Group";
|
||||
const groupName2 = "Test Group 2";
|
||||
const testMessage = "Test Message";
|
||||
|
||||
let connections = getConnections(3);
|
||||
connections[0].on(Constant.echo, deferMapList[0].callback());
|
||||
connections[1].on(Constant.echo, deferMapList[1].callback());
|
||||
connections[1].on(Constant.getConnectionId, deferMapList[1].callback(connectionIdPromiseName));
|
||||
connections[1].on(
|
||||
Constant.getConnectionId,
|
||||
deferMapList[1].callback(connectionIdPromiseName)
|
||||
);
|
||||
connections[2].on(Constant.echo, deferMapList[2].callback());
|
||||
await startConnections(connections);
|
||||
|
||||
// Connection0 / Connection1 join Group1
|
||||
let promise0 = deferMapList[0].waitForPromise(1);
|
||||
await connections[0].invoke(Constant.joinGroup, 'connection0', groupName)
|
||||
.catch(err => expect(err).toBeNull());
|
||||
await connections[0]
|
||||
.invoke(Constant.joinGroup, "connection0", groupName)
|
||||
.catch((err) => expect(err).toBeNull());
|
||||
await promise0;
|
||||
|
||||
let promise1 = deferMapList[1].waitForPromise(1);
|
||||
await connections[1].invoke(Constant.joinGroup, 'connection1', groupName)
|
||||
.catch(err => expect(err).toBeNull());
|
||||
await connections[1]
|
||||
.invoke(Constant.joinGroup, "connection1", groupName)
|
||||
.catch((err) => expect(err).toBeNull());
|
||||
await promise1;
|
||||
|
||||
promise0 = deferMapList[0].waitForPromise(3);
|
||||
promise1 = deferMapList[1].waitForPromise(2);
|
||||
await connections[0].invoke(Constant.sendGroup, 'connection0', groupName, testMessage);
|
||||
expect(await promise0).toEqual(['connection0', testMessage]);
|
||||
expect(await promise1).toEqual(['connection0', testMessage]);
|
||||
await connections[0].invoke(
|
||||
Constant.sendGroup,
|
||||
"connection0",
|
||||
groupName,
|
||||
testMessage
|
||||
);
|
||||
expect(await promise0).toEqual(["connection0", testMessage]);
|
||||
expect(await promise1).toEqual(["connection0", testMessage]);
|
||||
|
||||
// Connection2 join Group2 and send to Group1 and Group2
|
||||
let promise2 = deferMapList[2].waitForPromise(1);
|
||||
await connections[2].invoke(Constant.joinGroup, 'connection2', groupName2)
|
||||
.catch(err => expect(err).toBeNull());
|
||||
await connections[2]
|
||||
.invoke(Constant.joinGroup, "connection2", groupName2)
|
||||
.catch((err) => expect(err).toBeNull());
|
||||
await promise2;
|
||||
|
||||
promise0 = deferMapList[0].waitForPromise(4);
|
||||
promise1 = deferMapList[1].waitForPromise(3);
|
||||
promise2 = deferMapList[2].waitForPromise(2);
|
||||
await connections[2].invoke(Constant.sendGroups, 'connection2', [groupName, groupName2], testMessage);
|
||||
expect(await promise0).toEqual(['connection2', testMessage]);
|
||||
expect(await promise1).toEqual(['connection2', testMessage]);
|
||||
expect(await promise2).toEqual(['connection2', testMessage]);
|
||||
await connections[2].invoke(
|
||||
Constant.sendGroups,
|
||||
"connection2",
|
||||
[groupName, groupName2],
|
||||
testMessage
|
||||
);
|
||||
expect(await promise0).toEqual(["connection2", testMessage]);
|
||||
expect(await promise1).toEqual(["connection2", testMessage]);
|
||||
expect(await promise2).toEqual(["connection2", testMessage]);
|
||||
|
||||
// Get connection Id of connection1
|
||||
let connectionIdPromise = deferMapList[1].waitForPromise(connectionIdPromiseName);
|
||||
let connectionIdPromise = deferMapList[1].waitForPromise(
|
||||
connectionIdPromiseName
|
||||
);
|
||||
await connections[1].invoke(Constant.getConnectionId);
|
||||
let [connectionId1] = await connectionIdPromise;
|
||||
|
||||
promise0 = deferMapList[0].waitForPromise(5);
|
||||
promise1 = deferMapList[1].waitForPromise(4);
|
||||
await connections[1].invoke(Constant.sendGroupExcept, 'connection1', groupName, [connectionId1], testMessage);
|
||||
expect(await promise0).toEqual(['connection1', testMessage]);
|
||||
await connections[1].invoke(
|
||||
Constant.sendGroupExcept,
|
||||
"connection1",
|
||||
groupName,
|
||||
[connectionId1],
|
||||
testMessage
|
||||
);
|
||||
expect(await promise0).toEqual(["connection1", testMessage]);
|
||||
await promiseOrTimeout(promise1, Constant.awaitTimeout).catch((error) => {
|
||||
expect(error).not.toBeNull();
|
||||
});
|
||||
|
@ -104,10 +143,10 @@ test('send group / groups / group except', async () => {
|
|||
await stopConnections(connections);
|
||||
});
|
||||
|
||||
test('send others in group', async () => {
|
||||
test("send others in group", async () => {
|
||||
const deferMapList = [new DeferMap(), new DeferMap(), new DeferMap()];
|
||||
const groupName = 'Test Group';
|
||||
const testMessage = 'Test Message';
|
||||
const groupName = "Test Group";
|
||||
const testMessage = "Test Message";
|
||||
|
||||
let connections = getConnections(3);
|
||||
connections[0].on(Constant.echo, deferMapList[0].callback());
|
||||
|
@ -118,19 +157,24 @@ test('send others in group', async () => {
|
|||
let promise0 = deferMapList[0].waitForPromise(1);
|
||||
let promise1 = deferMapList[1].waitForPromise(1);
|
||||
let promise2 = deferMapList[2].waitForPromise(1);
|
||||
await connections[0].invoke(Constant.joinGroup, 'connection0', groupName);
|
||||
await connections[0].invoke(Constant.joinGroup, "connection0", groupName);
|
||||
await promise0;
|
||||
await connections[1].invoke(Constant.joinGroup, 'connection1', groupName);
|
||||
await connections[1].invoke(Constant.joinGroup, "connection1", groupName);
|
||||
await promise1;
|
||||
await connections[2].invoke(Constant.joinGroup, 'connection2', groupName);
|
||||
await connections[2].invoke(Constant.joinGroup, "connection2", groupName);
|
||||
await promise2;
|
||||
|
||||
promise0 = deferMapList[0].waitForPromise(4);
|
||||
promise1 = deferMapList[1].waitForPromise(3);
|
||||
promise2 = deferMapList[2].waitForPromise(2);
|
||||
await connections[0].invoke(Constant.sendOthersInGroup, 'connection0', groupName, testMessage);
|
||||
expect(await promise1).toEqual(['connection0', testMessage]);
|
||||
expect(await promise2).toEqual(['connection0', testMessage]);
|
||||
await connections[0].invoke(
|
||||
Constant.sendOthersInGroup,
|
||||
"connection0",
|
||||
groupName,
|
||||
testMessage
|
||||
);
|
||||
expect(await promise1).toEqual(["connection0", testMessage]);
|
||||
expect(await promise2).toEqual(["connection0", testMessage]);
|
||||
await promiseOrTimeout(promise0, Constant.awaitTimeout).catch((error) => {
|
||||
expect(error).not.toBeNull();
|
||||
});
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { getConnections, startConnections, stopConnections } from "./utils";
|
||||
import { Constant } from "./constant";
|
||||
|
||||
const semver = require('semver');
|
||||
const semver = require("semver");
|
||||
var sdkVerion = process.env.SDKVersion;
|
||||
// Skip tests for service SDK before version 1.0.0-preview1-10197
|
||||
if (semver.gte(sdkVerion, '1.0.0-preview1-10197')) {
|
||||
test('HttpRequest.Request.Path is preserved', async () => {
|
||||
if (semver.gte(sdkVerion, "1.0.0-preview1-10197")) {
|
||||
test("HttpRequest.Request.Path is preserved", async () => {
|
||||
let path: string;
|
||||
const connections = getConnections(1);
|
||||
await startConnections(connections);
|
||||
|
@ -14,17 +14,19 @@ if (semver.gte(sdkVerion, '1.0.0-preview1-10197')) {
|
|||
await stopConnections(connections);
|
||||
});
|
||||
|
||||
test('HttpRequest.Request.QueryString is preserved', async () => {
|
||||
test("HttpRequest.Request.QueryString is preserved", async () => {
|
||||
let queryString: string;
|
||||
const connections = getConnections(1, Constant.Server.ChatUrl + "?customName=customValue");
|
||||
const connections = getConnections(
|
||||
1,
|
||||
Constant.Server.ChatUrl + "?customName=customValue"
|
||||
);
|
||||
await startConnections(connections);
|
||||
queryString = await connections[0].invoke("getQueryString");
|
||||
expect(queryString).toContain("&customName=customValue&");
|
||||
await stopConnections(connections);
|
||||
});
|
||||
}
|
||||
else {
|
||||
test('Fake test', async () => {
|
||||
} else {
|
||||
test("Fake test", async () => {
|
||||
expect(1).toBe(1);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
import { getConnections, startConnections, stopConnections } from "./utils";
|
||||
import { Constant } from "./constant";
|
||||
|
||||
const testMessage = 'Test Message';
|
||||
const testMessage = "Test Message";
|
||||
|
||||
test('generic hub', async () => {
|
||||
test("generic hub", async () => {
|
||||
const connections = getConnections(1, `${Constant.Server.Host}/genericchat`);
|
||||
const connectionName = 'connection';
|
||||
const connectionName = "connection";
|
||||
|
||||
const echoCallback = jest.fn();
|
||||
connections[0].on('echo', echoCallback);
|
||||
connections[0].on("echo", echoCallback);
|
||||
|
||||
await startConnections(connections);
|
||||
|
||||
await connections[0].invoke('echo', connectionName, testMessage);
|
||||
await connections[0].invoke("echo", connectionName, testMessage);
|
||||
|
||||
expect(echoCallback).toBeCalledWith(connectionName, testMessage);
|
||||
await stopConnections(connections);
|
||||
});
|
||||
|
||||
test('long name hub with length 128', async () => {
|
||||
test("long name hub with length 128", async () => {
|
||||
const connections = getConnections(1, `${Constant.Server.Host}/longnamechat`);
|
||||
const connectionName = 'connection';
|
||||
const connectionName = "connection";
|
||||
|
||||
const echoCallback = jest.fn();
|
||||
connections[0].on('echo', echoCallback);
|
||||
connections[0].on("echo", echoCallback);
|
||||
|
||||
await startConnections(connections);
|
||||
|
||||
await connections[0].invoke('echo', connectionName, testMessage);
|
||||
await connections[0].invoke("echo", connectionName, testMessage);
|
||||
|
||||
expect(echoCallback).toBeCalledWith(connectionName, testMessage);
|
||||
await stopConnections(connections);
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
import { delay, getConnections, startConnections, DeferMap, promiseOrTimeout, stopConnections } from './utils';
|
||||
import {
|
||||
delay,
|
||||
getConnections,
|
||||
startConnections,
|
||||
DeferMap,
|
||||
promiseOrTimeout,
|
||||
stopConnections,
|
||||
} from "./utils";
|
||||
import { Constant } from "./constant";
|
||||
|
||||
test('send user and users', async () => {
|
||||
test("send user and users", async () => {
|
||||
const deferMapList = [new DeferMap(), new DeferMap()];
|
||||
const testMessage = 'Test Message';
|
||||
const testMessage = "Test Message";
|
||||
|
||||
let connections = getConnections(2);
|
||||
connections[0].on(Constant.echo, deferMapList[0].callback());
|
||||
|
@ -12,13 +19,25 @@ test('send user and users', async () => {
|
|||
|
||||
let promise0 = deferMapList[0].waitForPromise(1);
|
||||
let promise1 = deferMapList[1].waitForPromise(1);
|
||||
await connections[0].invoke(Constant.sendUser, 'connection0', 'user0', testMessage);
|
||||
expect(await promise0).toEqual(['connection0', testMessage]);
|
||||
await promiseOrTimeout(promise1, Constant.awaitTimeout).catch(error => expect(error).not.toBeNull());
|
||||
await connections[0].invoke(
|
||||
Constant.sendUser,
|
||||
"connection0",
|
||||
"user0",
|
||||
testMessage
|
||||
);
|
||||
expect(await promise0).toEqual(["connection0", testMessage]);
|
||||
await promiseOrTimeout(promise1, Constant.awaitTimeout).catch((error) =>
|
||||
expect(error).not.toBeNull()
|
||||
);
|
||||
|
||||
promise0 = deferMapList[0].waitForPromise(2);
|
||||
await connections[1].invoke(Constant.sendUsers, 'connection1', ['user0', 'user1'], testMessage);
|
||||
expect(await promise0).toEqual(['connection1', testMessage]);
|
||||
expect(await promise1).toEqual(['connection1', testMessage]);
|
||||
await connections[1].invoke(
|
||||
Constant.sendUsers,
|
||||
"connection1",
|
||||
["user0", "user1"],
|
||||
testMessage
|
||||
);
|
||||
expect(await promise0).toEqual(["connection1", testMessage]);
|
||||
expect(await promise1).toEqual(["connection1", testMessage]);
|
||||
await stopConnections(connections);
|
||||
});
|
||||
|
|
|
@ -5,18 +5,23 @@ import * as signalR from "@aspnet/signalr";
|
|||
import { Constant } from "./constant";
|
||||
|
||||
function appendQueryParameter(url: string, name: string, value: string) {
|
||||
var separator = url.indexOf('?') === -1 ? '?' : '&';
|
||||
return `${url}${separator}${name}=${value}`
|
||||
var separator = url.indexOf("?") === -1 ? "?" : "&";
|
||||
return `${url}${separator}${name}=${value}`;
|
||||
}
|
||||
|
||||
async function delay(milliseconds: number) {
|
||||
return new Promise<void>(resolve => {
|
||||
return new Promise<void>((resolve) => {
|
||||
setTimeout(resolve, milliseconds);
|
||||
});
|
||||
}
|
||||
|
||||
function getConnections(count : number, url = Constant.Server.ChatUrl, usernameFactory? : (number) => string, accessTokenFactory? : () => string | Promise<string>){
|
||||
let connections : HubConnection[] = new Array(count);
|
||||
function getConnections(
|
||||
count: number,
|
||||
url = Constant.Server.ChatUrl,
|
||||
usernameFactory?: (number) => string,
|
||||
accessTokenFactory?: () => string | Promise<string>
|
||||
) {
|
||||
let connections: HubConnection[] = new Array(count);
|
||||
for (let i = 0; i < connections.length; i++) {
|
||||
let username: string;
|
||||
if (usernameFactory != null) {
|
||||
|
@ -25,8 +30,9 @@ function getConnections(count : number, url = Constant.Server.ChatUrl, usernameF
|
|||
username = `user${i}`;
|
||||
}
|
||||
connections[i] = new signalR.HubConnectionBuilder()
|
||||
.withUrl(appendQueryParameter(url, 'username', username), {
|
||||
accessTokenFactory: accessTokenFactory == null ? () => "" : accessTokenFactory
|
||||
.withUrl(appendQueryParameter(url, "username", username), {
|
||||
accessTokenFactory:
|
||||
accessTokenFactory == null ? () => "" : accessTokenFactory,
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
@ -36,7 +42,7 @@ function getConnections(count : number, url = Constant.Server.ChatUrl, usernameF
|
|||
async function startConnections(connections: HubConnection[]) {
|
||||
let promise = new Array(connections.length);
|
||||
for (let i in connections) {
|
||||
promise[i] = connections[i].start().catch(err => expect(err).toBeNull());
|
||||
promise[i] = connections[i].start().catch((err) => expect(err).toBeNull());
|
||||
}
|
||||
await Promise.all(promise);
|
||||
}
|
||||
|
@ -52,18 +58,22 @@ async function stopConnections(connections: HubConnection[]) {
|
|||
async function promiseOrTimeout(promise: Promise<void>, timeout: number) {
|
||||
return Promise.race([
|
||||
promise,
|
||||
new Promise((_, reject) => setTimeout(() => reject(new Error('Timeout')), timeout))
|
||||
])
|
||||
new Promise((_, reject) =>
|
||||
setTimeout(() => reject(new Error("Timeout")), timeout)
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
function Deferred() {
|
||||
this.resolve = null;
|
||||
this.reject = null;
|
||||
|
||||
this.promise = new Promise(function (resolve, reject) {
|
||||
this.promise = new Promise(
|
||||
function (resolve, reject) {
|
||||
this.resolve = resolve;
|
||||
this.reject = reject;
|
||||
}.bind(this));
|
||||
}.bind(this)
|
||||
);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
|
@ -103,4 +113,12 @@ class DeferMap {
|
|||
};
|
||||
}
|
||||
|
||||
export { delay, getConnections, startConnections, stopConnections, promiseOrTimeout, Deferred, DeferMap };
|
||||
export {
|
||||
delay,
|
||||
getConnections,
|
||||
startConnections,
|
||||
stopConnections,
|
||||
promiseOrTimeout,
|
||||
Deferred,
|
||||
DeferMap,
|
||||
};
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
# .npmrc
|
||||
engine-strict=true
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -2,7 +2,7 @@
|
|||
"name": "azure-signalr-test",
|
||||
"version": "0.1.0",
|
||||
"scripts": {
|
||||
"test": "jest -w 1"
|
||||
"test": "jest -w 1 --forceExit"
|
||||
},
|
||||
"jest": {
|
||||
"setupTestFrameworkScriptFile": "./jest.setup.ts",
|
||||
|
@ -23,6 +23,10 @@
|
|||
"jest-junit"
|
||||
]
|
||||
},
|
||||
"engines": {
|
||||
"npm": ">=8.0.0 <9.0.0",
|
||||
"node": ">=16.0.0 <17.0.0"
|
||||
},
|
||||
"jest-junit": {
|
||||
"suiteName": "jest tests",
|
||||
"outputDirectory": ".",
|
||||
|
@ -38,7 +42,7 @@
|
|||
"jest": "^23.5.0",
|
||||
"jest-junit": "^5.2.0",
|
||||
"njwt": "^0.4.0",
|
||||
"npm": "^6.4.0",
|
||||
"npm": "^8.0.0",
|
||||
"request": "^2.88.0",
|
||||
"request-promise": "^4.2.2",
|
||||
"semver": "^5.5.1",
|
||||
|
|
|
@ -2,12 +2,17 @@ import { getConnections, startConnections, stopConnections } from "./utils";
|
|||
import { Constant } from "./constant";
|
||||
import * as request from "request-promise";
|
||||
|
||||
function AadTokenFactory() : Promise<string> {
|
||||
function AadTokenFactory(): Promise<string> {
|
||||
return request(`${Constant.Server.Host}/aad/login`);
|
||||
}
|
||||
|
||||
test('connect to server with aad token', async () => {
|
||||
const connections = getConnections(1, Constant.Server.ChatUrl, null, AadTokenFactory);
|
||||
test("connect to server with aad token", async () => {
|
||||
const connections = getConnections(
|
||||
1,
|
||||
Constant.Server.ChatUrl,
|
||||
null,
|
||||
AadTokenFactory
|
||||
);
|
||||
await startConnections(connections);
|
||||
await stopConnections(connections);
|
||||
});
|
|
@ -0,0 +1,2 @@
|
|||
# .npmrc
|
||||
engine-strict=true
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -2,7 +2,7 @@
|
|||
"name": "azure-signalr-test",
|
||||
"version": "0.1.0",
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
"test": "jest -w 1"
|
||||
},
|
||||
"jest": {
|
||||
"testEnvironment": "node",
|
||||
|
@ -24,6 +24,10 @@
|
|||
"jest-junit"
|
||||
]
|
||||
},
|
||||
"engines": {
|
||||
"npm": ">=8.0.0 <9.0.0",
|
||||
"node": ">=16.0.0 <17.0.0"
|
||||
},
|
||||
"jest-junit": {
|
||||
"suiteName": "jest tests",
|
||||
"outputDirectory": ".",
|
||||
|
@ -39,7 +43,7 @@
|
|||
"jest": "^23.5.0",
|
||||
"jest-junit": "^5.2.0",
|
||||
"njwt": "^0.4.0",
|
||||
"npm": "^6.14.14",
|
||||
"npm": "^8.0.0",
|
||||
"request": "^2.88.0",
|
||||
"request-promise": "^4.2.2",
|
||||
"semver": "^5.5.1",
|
||||
|
|
|
@ -8,7 +8,7 @@ pushd ${DIR}
|
|||
# Build the base docker image
|
||||
docker build -t signalr-test-base -f ./RuntimeBase.Dockerfile .
|
||||
|
||||
declare -a SDKVersion=("1.0.14" "1.2.3" "1.4.3" "1.5.1" "1.8.2" "1.9.0" "1.10.0" "1.11.0")
|
||||
declare -a SDKVersion=("1.10.0" "1.11.0" "1.12.0" "1.13.0" "1.14.0" "1.15.2" "1.16.1" "1.17.1" "1.18.3")
|
||||
|
||||
for version in "${SDKVersion[@]}"; do
|
||||
docker build -t signalr-management-sdk-test:$version -f ./ManagementE2ETest/Dockerfile --build-arg SDKVersion=$version .
|
||||
|
|
|
@ -8,7 +8,7 @@ pushd ${DIR}
|
|||
# Build the base docker image
|
||||
docker build -t signalr-test-base -f ./RuntimeBase.Dockerfile .
|
||||
|
||||
declare -a SDKVersion=("1.0.14" "1.2.3" "1.4.3" "1.5.1" "1.8.2" "1.9.0" "1.10.0" "1.11.0")
|
||||
declare -a SDKVersion=("1.10.0" "1.11.0" "1.12.0" "1.13.0" "1.14.0" "1.15.2" "1.16.1" "1.17.1" "1.18.3")
|
||||
|
||||
for version in "${SDKVersion[@]}"; do
|
||||
echo $version
|
||||
|
|
Загрузка…
Ссылка в новой задаче