Skip to content

Commit a74a934

Browse files
committed
test/repetitions: removed unnecessary use of setTimeout
1 parent 2dc2c1a commit a74a934

File tree

1 file changed

+21
-50
lines changed

1 file changed

+21
-50
lines changed

test/repetitions.js

Lines changed: 21 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,11 @@ module.exports = {
99
for (var i = 0; i < EXPECTED; i++) {
1010
bcrypt.genSalt(10, function(err, salt) {
1111
assert.equals(29, salt.length, "Salt ("+salt+") isn't the correct length. It is: " + salt.length);
12-
n++;
13-
});
14-
}
15-
16-
function checkVal() {
17-
if (n == EXPECTED) {
18-
assert.done();
19-
} else {
20-
setTimeout(checkVal, 100);
12+
if (++n == EXPECTED) {
13+
assert.done();
2114
}
15+
});
2216
}
23-
setTimeout(checkVal, 100);
2417
},
2518
test_hash_length: function(assert) {
2619
assert.expect(EXPECTED);
@@ -29,18 +22,11 @@ module.exports = {
2922
for (var i = 0; i < EXPECTED; i++) {
3023
bcrypt.hash('test', SALT, function(err, crypted) {
3124
assert.equals(60, crypted.length, "Encrypted ("+crypted+") isn't the correct length. It is: " + crypted.length);
32-
n++;
25+
if (++n == EXPECTED) {
26+
assert.done();
27+
}
3328
});
3429
}
35-
36-
function checkVal() {
37-
if (n == EXPECTED) {
38-
assert.done();
39-
} else {
40-
setTimeout(checkVal, 100);
41-
}
42-
}
43-
setTimeout(checkVal, 100);
4430
},
4531
test_compare: function(assert) {
4632
assert.expect(EXPECTED);
@@ -49,18 +35,11 @@ module.exports = {
4935
for (var i = 0; i < EXPECTED; i++) {
5036
bcrypt.compare('test', HASH, function(err, match) {
5137
assert.equal(true, match, "No match.");
52-
n++;
38+
if (++n == EXPECTED) {
39+
assert.done();
40+
}
5341
});
5442
}
55-
56-
function checkVal() {
57-
if (n == EXPECTED) {
58-
assert.done();
59-
} else {
60-
setTimeout(checkVal, 100);
61-
}
62-
}
63-
setTimeout(checkVal, 100);
6443
},
6544
test_hash_and_compare: function(assert) {
6645
assert.expect((EXPECTED-1)*3);
@@ -87,29 +66,21 @@ module.exports = {
8766
if (idx >= (EXPECTED-1)) {
8867
good_done = true;
8968
}
90-
});
9169

92-
bcrypt.compare('bad' + password, hash, function(err, res) {
93-
//if (err) throw err;
94-
assert.ok(!res);
95-
if (idx >= (EXPECTED-1)) {
96-
bad_done = true;
97-
}
98-
});
99-
100-
if (idx < ((EXPECTED)-1)) {
101-
next();
102-
} else {
103-
function checkDone() {
104-
if (idx >= (EXPECTED-1) && good_done && bad_done) {
105-
assert.done();
106-
} else {
107-
setTimeout(checkDone, 100);
70+
bcrypt.compare('bad' + password, hash, function(err, res) {
71+
//if (err) throw err;
72+
assert.ok(!res);
73+
if (idx >= (EXPECTED-1)) {
74+
bad_done = true;
10875
}
109-
}
11076

111-
setTimeout(checkDone, 100);
112-
}
77+
if (idx < ((EXPECTED)-1)) {
78+
next();
79+
} else {
80+
assert.done();
81+
}
82+
});
83+
});
11384
});
11485
}
11586

0 commit comments

Comments
 (0)