Skip to content

Commit eaecfc2

Browse files
committed
test connections
1 parent 7b16ec7 commit eaecfc2

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

integration/test/ParseServerTest.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ describe('ParseServer', () => {
1515
parseServer.server.on('close', () => {
1616
close += 1;
1717
});
18-
const object = new TestObject({ foo: 'bar' });
18+
const object = new TestObject();
19+
// Open a connection to the server
20+
const query = new Parse.Query(TestObject);
21+
await query.subscribe();
22+
expect(openConnections.size > 0).toBeTruthy();
1923
await shutdownServer(parseServer);
2024
expect(close).toBe(1);
25+
expect(openConnections.size).toBe(0);
2126
await expectAsync(object.save()).toBeRejectedWithError(
2227
'XMLHttpRequest failed: "Unable to connect to the Parse API"'
2328
);

integration/test/helper.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const defaultConfiguration = {
9393
}),
9494
};
9595

96-
const openConnections = {};
96+
const openConnections = new Set();
9797
let parseServer;
9898

9999
const shutdownServer = async _parseServer => {
@@ -138,10 +138,9 @@ const reconfigureServer = async (changedConfiguration = {}) => {
138138
});
139139
}
140140
parseServer.server.on('connection', connection => {
141-
const key = `${connection.remoteAddress}:${connection.remotePort}`;
142-
openConnections[key] = connection;
141+
openConnections.add(connection);
143142
connection.on('close', () => {
144-
delete openConnections[key];
143+
openConnections.delete(connection);
145144
});
146145
});
147146
return parseServer;
@@ -155,6 +154,7 @@ global.TestPoint = Parse.Object.extend('TestPoint');
155154
global.TestObject = Parse.Object.extend('TestObject');
156155
global.reconfigureServer = reconfigureServer;
157156
global.shutdownServer = shutdownServer;
157+
global.openConnections = openConnections;
158158

159159
beforeAll(async () => {
160160
const promise = ['parse.js', 'parse.min.js'].map(fileName => {
@@ -179,11 +179,4 @@ afterEach(async () => {
179179
}
180180
});
181181

182-
afterAll(() => {
183-
// Jasmine process counts as one open connection
184-
if (Object.keys(openConnections).length > 1) {
185-
console.warn('There were open connections to the server left after the test finished');
186-
}
187-
});
188-
189182
module.exports = { twitterAuthData };

0 commit comments

Comments
 (0)