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: Remove unnecessary setTimeout and reconfigureServer calls #9183

Merged
merged 7 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion spec/CLI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ describe('execution', () => {
);
childProcess.stdout.on('data', data => {
data = data.toString();
console.log(data);
if (data.includes('parse-server running on')) {
done();
}
Expand Down
1 change: 0 additions & 1 deletion spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9709,7 +9709,6 @@ describe('ParseGraphQLServer', () => {
});
expect(res.status).toEqual(200);
const result = await res.json();
console.log(result);
expect(result.data.createSomeClass.someClass.someFileField.name).toEqual(
jasmine.stringMatching(/_someFileField.txt$/)
);
Expand Down
95 changes: 14 additions & 81 deletions spec/ParseLiveQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const UserController = require('../lib/Controllers/UserController').UserControll
const Config = require('../lib/Config');
const ParseServer = require('../lib/index').ParseServer;
const triggers = require('../lib/triggers');
const { resolvingPromise, sleep } = require('./support/testUtils');
const validatorFail = () => {
throw 'you are not authorized';
};
Expand All @@ -14,19 +15,9 @@ describe('ParseLiveQuery', function () {
});
afterEach(async () => {
const client = await Parse.CoreManager.getLiveQueryController().getDefaultLiveQueryClient();
client.close();
// Wait for live query client to disconnect
await new Promise(resolve => setTimeout(resolve, 1000));
await client.close();
});
it('access user on onLiveQueryEvent disconnect', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
const requestedUser = new Parse.User();
requestedUser.setUsername('username');
requestedUser.setPassword('password');
Expand All @@ -43,18 +34,10 @@ describe('ParseLiveQuery', function () {
const query = new Parse.Query(TestObject);
await query.subscribe();
const client = await Parse.CoreManager.getLiveQueryController().getDefaultLiveQueryClient();
client.close();
await client.close();
});

it('can subscribe to query', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
const object = new TestObject();
await object.save();

Expand Down Expand Up @@ -120,14 +103,6 @@ describe('ParseLiveQuery', function () {
});

it('expect afterEvent payload', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
const object = new TestObject();
await object.save();

Expand All @@ -147,14 +122,6 @@ describe('ParseLiveQuery', function () {
});

it('expect afterEvent enter', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
Parse.Cloud.afterLiveQueryEvent('TestObject', req => {
expect(req.event).toBe('enter');
expect(req.user).toBeUndefined();
Expand All @@ -178,14 +145,6 @@ describe('ParseLiveQuery', function () {
});

it('expect afterEvent leave', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
Parse.Cloud.afterLiveQueryEvent('TestObject', req => {
expect(req.event).toBe('leave');
expect(req.user).toBeUndefined();
Expand All @@ -210,14 +169,6 @@ describe('ParseLiveQuery', function () {
});

it('expect afterEvent delete', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
Parse.Cloud.afterLiveQueryEvent('TestObject', req => {
expect(req.event).toBe('delete');
expect(req.user).toBeUndefined();
Expand Down Expand Up @@ -365,30 +316,18 @@ describe('ParseLiveQuery', function () {
);
});

it('can handle afterEvent sendEvent to false', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});

it('can handle afterEvent sendEvent to false', async () => {
const object = new TestObject();
await object.save();

const promise = resolvingPromise();
Parse.Cloud.afterLiveQueryEvent('TestObject', req => {
const current = req.object;
const original = req.original;

setTimeout(() => {
done();
}, 2000);

if (current.get('foo') != original.get('foo')) {
req.sendEvent = false;
}
promise.resolve();
});

const query = new Parse.Query(TestObject);
Expand All @@ -402,9 +341,10 @@ describe('ParseLiveQuery', function () {
});
object.set({ foo: 'bar' });
await object.save();
await promise;
});

xit('can handle live query with fields - enable upon JS SDK support', async () => {
it('can handle live query with fields', async () => {
await reconfigureServer({
liveQuery: {
classNames: ['Test'],
Expand Down Expand Up @@ -442,7 +382,7 @@ describe('ParseLiveQuery', function () {
await obj2.save();
obj2.set('foo', 'bart');
await obj2.save();
await new Promise(resolve => setTimeout(resolve, 2000));
await sleep(2000);
expect(createSpy).toHaveBeenCalledTimes(1);
expect(updateSpy).toHaveBeenCalledTimes(1);
});
Expand Down Expand Up @@ -771,14 +711,6 @@ describe('ParseLiveQuery', function () {
});

it('can handle select beforeSubscribe query', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
Parse.Cloud.beforeSubscribe(TestObject, request => {
const query = request.query;
query.select('yolo');
Expand Down Expand Up @@ -857,7 +789,7 @@ describe('ParseLiveQuery', function () {
object.set({ foo: 'bar' });
await object.save();
await object.destroy();
await new Promise(resolve => setTimeout(resolve, 200));
await sleep(200);
for (const key in calls) {
expect(calls[key]).toHaveBeenCalled();
}
Expand Down Expand Up @@ -891,9 +823,9 @@ describe('ParseLiveQuery', function () {
object.set({ foo: 'bar' });
await object.save(null, { useMasterKey: true });
role.getUsers().add(user);
await new Promise(resolve => setTimeout(resolve, 1000));
await sleep(1000);
await role.save();
await new Promise(resolve => setTimeout(resolve, 1000));
await sleep(1000);
object.set('foo', 'yolo');
await Promise.all([
new Promise(resolve => {
Expand Down Expand Up @@ -924,7 +856,6 @@ describe('ParseLiveQuery', function () {
const subscription = await query.subscribe();

subscription.on('create', async obj => {
await new Promise(resolve => setTimeout(resolve, 200));
expect(obj.get('user').id).toBe(user.id);
expect(obj.get('createdWith')).toEqual({ action: 'login', authProvider: 'password' });
expect(obj.get('expiresAt')).toBeInstanceOf(Date);
Expand Down Expand Up @@ -1227,6 +1158,8 @@ describe('ParseLiveQuery', function () {
classNames: ['Yolo'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
};
if (process.env.PARSE_SERVER_TEST_DB === 'postgres') {
config.databaseAdapter = new databaseAdapter.constructor({
Expand Down
4 changes: 2 additions & 2 deletions spec/ParseQuery.Comment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ describe_only_db('mongo')('Parse.Query with comment testing', () => {
database = client.db('parseServerMongoAdapterTestDatabase');
let profiler = await database.command({ profile: 0 });
expect(profiler.was).toEqual(0);
console.log(`Disabling profiler : ${profiler.was}`);
// console.log(`Disabling profiler : ${profiler.was}`);
profiler = await database.command({ profile: profileLevel });
profiler = await database.command({ profile: -1 });
console.log(`Enabling profiler : ${profiler.was}`);
// console.log(`Enabling profiler : ${profiler.was}`);
profiler = await database.command({ profile: -1 });
expect(profiler.was).toEqual(profileLevel);
});
Expand Down
1 change: 1 addition & 0 deletions spec/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const defaultConfiguration = {
fileKey: 'test',
directAccess: true,
silent,
verbose: !silent,
logLevel,
liveQuery: {
classNames: ['TestObject'],
Expand Down
18 changes: 18 additions & 0 deletions spec/support/testUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Create Deferred Promise
function resolvingPromise() {
let res;
let rej;
const promise = new Promise((resolve, reject) => {
res = resolve;
rej = reject;
});
promise.resolve = res;
promise.reject = rej;
return promise;
}

function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

module.exports = { resolvingPromise, sleep };
Loading