Skip to content

Commit

Permalink
fix local tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Jul 23, 2024
1 parent 4912617 commit 788c73d
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions test/db.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const dummy = () => {
// dummy/empty function;
};

const isLocalPC = process.env.NODE_ENV === 'development';

function isResult(value) {
if (options.pgNative) {
// Impossible to test, because pg-native fails to export the Result type;
Expand Down Expand Up @@ -169,12 +171,14 @@ describe('Connection', () => {
expect(log.e.cn).toEqual(errCN);
expect(result instanceof Error).toBe(true);

if (options.pgNative) {
expect(result.message).toContain('could not connect to server');
} else {
expect(result.message).toContain('connect ECONNREFUSED');
if (!isLocalPC) {
// these errors differ between Windows 11 and Linux :|
if (options.pgNative) {
expect(result.message).toContain('could not connect to server');
} else {
expect(result.message).toContain('connect ECONNREFUSED');
}
}

});
});
describe('with transaction connection', () => {
Expand All @@ -187,10 +191,14 @@ describe('Connection', () => {
});
it('must report the right error', () => {
expect(result instanceof Error).toBe(true);
if (options.pgNative) {
expect(result.message).toContain('could not connect to server');
} else {
expect(result.message).toContain('connect ECONNREFUSED');

if (!isLocalPC) {
// these errors differ between Windows 11 and Linux :|
if (options.pgNative) {
expect(result.message).toContain('could not connect to server');
} else {
expect(result.message).toContain('connect ECONNREFUSED');
}
}
});
});
Expand All @@ -213,10 +221,14 @@ describe('Connection', () => {
});
it('must report the right error', () => {
expect(result instanceof Error).toBe(true);
if (options.pgNative) {
expect(result.message).toContain('could not connect to server');
} else {
expect(result.message).toContain('connect ECONNREFUSED');

if (!isLocalPC) {
// these errors differ between Windows 11 and Linux :|
if (options.pgNative) {
expect(result.message).toContain('could not connect to server');
} else {
expect(result.message).toContain('connect ECONNREFUSED');
}
}
});
});
Expand Down Expand Up @@ -365,8 +377,8 @@ describe('Connection', () => {
.catch(reason => {
error = reason;
}), // Terminate connection after a short delay, before the query finishes
promise.delay(1000)
.then(() => dbSpec.one('SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid = $1', pid))])
promise.delay(1000)
.then(() => dbSpec.one('SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid = $1', pid))])
.finally(() => {
obj.done(error);
done();
Expand Down Expand Up @@ -452,10 +464,14 @@ describe('Direct Connection', () => {
});
it('must report the right error', () => {
expect(result instanceof Error).toBe(true);
if (options.pgNative) {
expect(result.message).toContain('could not connect to server');
} else {
expect(result.message).toContain('connect ECONNREFUSED');

if (!isLocalPC) {
// these errors differ between Windows 11 and Linux :|
if (options.pgNative) {
expect(result.message).toContain('could not connect to server');
} else {
expect(result.message).toContain('connect ECONNREFUSED');
}
}
});
});
Expand Down Expand Up @@ -1289,7 +1305,7 @@ describe('Transactions', () => {
return promise.all([dbSpec.one(`select count(*)
from users
where login = $1`, 'Test'), // 0 is expected;
dbSpec.one(`select count(*)
dbSpec.one(`select count(*)
from person
where name = $1`, 'Test') // 0 is expected;
]);
Expand Down Expand Up @@ -1497,11 +1513,11 @@ describe('Transactions', () => {
}, reason => {
error = reason;
}), // Terminate the connections during verify, which causes an 'error' event from the pool
promise.delay(500).then(() => {
return dbSpec.query(`SELECT pg_terminate_backend(pid)
promise.delay(500).then(() => {
return dbSpec.query(`SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE pid <> pg_backend_pid();`);
})]).then(() => {
})]).then(() => {
done();
}, (err) => {
done(err);
Expand Down

0 comments on commit 788c73d

Please sign in to comment.