Skip to content
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

test: liveQueryPublisher should disconnect from Redis on shutdown #7368

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions spec/ParseServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const express = require('express');
const MongoStorageAdapter = require('../lib/Adapters/Storage/Mongo/MongoStorageAdapter').default;
const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/PostgresStorageAdapter')
.default;
const GridFSBucketAdapter = require('../lib/Adapters/Files/GridFSBucketAdapter')
.GridFSBucketAdapter;
const FSAdapter = require('@parse/fs-files-adapter');
const ParseServer = require('../lib/ParseServer').default;
const path = require('path');
const { spawn } = require('child_process');
Expand Down Expand Up @@ -114,3 +117,53 @@ describe('Server Url Checks', () => {
});
});
});

describe('Server Shutdown', () => {
let quitSpy;
let databaseAdapter;
let filesAdapter;

beforeEach(() => {
// Mock redis
quitSpy = jasmine.createSpy('quit'); // Called when connection is closed
const createClient = jasmine.createSpy('createClient').and.returnValue({
quit: quitSpy,
});
jasmine.mockLibrary('redis', 'createClient', createClient);

const mongoURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase';
const postgresURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database';

const isPostgres = process.env.PARSE_SERVER_TEST_DB === 'postgres';
databaseAdapter = isPostgres
? new PostgresStorageAdapter({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if instantiating a new DB adapter with custom settings outside of the test framework could have any side effects regarding cleanup, etc.

@dplewis ?

uri: process.env.PARSE_SERVER_TEST_DATABASE_URI || postgresURI,
collectionPrefix: 'shutdown_',
})
: new MongoStorageAdapter({
uri: mongoURI,
collectionPrefix: 'shutdown_',
});
filesAdapter = isPostgres ? new FSAdapter() : new GridFSBucketAdapter(mongoURI);
});

it('should disconnect from Redis', async () => {
const server = new ParseServer({
appId: 'test',
masterKey: 'test',
databaseAdapter,
filesAdapter,
liveQuery: {
redisURL: 'redis://127.0.0.1:6379', // Fake connection. URL is irrelevant
},
});

await server.handleShutdown();

expect(quitSpy).toHaveBeenCalled();
});

afterEach(function () {
jasmine.restoreLibrary('redis', 'createClient');
});
});