Skip to content

Commit 0b4c066

Browse files
authored
Merge pull request #366 from hgourvest/copilot/fix-test-errors-action-run
Fix test suite hanging indefinitely by adding timeouts and proper cleanup
2 parents cb38f90 + 60770b4 commit 0b4c066

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

.mocharc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"timeout": 10000,
3+
"exit": true
4+
}

test/index.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,24 @@ describe('Connection', function () {
1818
});
1919

2020
it('should reconnect when socket is closed', function (done) {
21+
this.timeout(5000);
2122
Firebird.attach(config, function (err, db) {
2223
assert.ok(!err, err);
2324

2425
db.connection._socket.destroy();
2526

26-
db.on('reconnect', function () {
27+
var reconnectHandler = function () {
28+
db.removeListener('error', errorHandler);
2729
db.detach(done);
28-
});
30+
};
31+
32+
var errorHandler = function (err) {
33+
db.removeListener('reconnect', reconnectHandler);
34+
done(err);
35+
};
36+
37+
db.on('reconnect', reconnectHandler);
38+
db.on('error', errorHandler);
2939
});
3040
});
3141

@@ -87,9 +97,11 @@ describe('Events', function () {
8797
});
8898
});
8999

90-
after(function () {
100+
after(function (done) {
91101
if (db) {
92-
db.detach();
102+
db.detach(done);
103+
} else {
104+
done();
93105
}
94106
});
95107

@@ -261,8 +273,12 @@ describe('Database', function() {
261273
});
262274
});
263275

264-
after(function() {
265-
if (db) db.detach();
276+
after(function(done) {
277+
if (db) {
278+
db.detach(done);
279+
} else {
280+
done();
281+
}
266282
});
267283

268284
describe('Select', function() {
@@ -582,8 +598,12 @@ describe('Database', function() {
582598
});
583599
});
584600

585-
after(function() {
586-
if (db) db.detach();
601+
after(function(done) {
602+
if (db) {
603+
db.detach(done);
604+
} else {
605+
done();
606+
}
587607
});
588608

589609
it('should create table2', function(done) {
@@ -792,8 +812,12 @@ describe('GDSCode in errors', function () {
792812
});
793813
});
794814

795-
after(function () {
796-
if (db) db.detach();
815+
after(function (done) {
816+
if (db) {
817+
db.detach(done);
818+
} else {
819+
done();
820+
}
797821
});
798822

799823
it('should return gdscode', function (done) {

0 commit comments

Comments
 (0)