Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 646399f

Browse files
committed
Change stress test code
1 parent a07b93a commit 646399f

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

test/test-0.6.3.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,40 @@ describe('massive HTTP request', (report, done) => {
3131

3232
let promises = []
3333
let progress = []
34+
let iteration = 500
3435
let begin = Date.now()
35-
for(let i=0; i<500;i++) {
36+
let finished = 0
37+
let success = 0
38+
for(let i=0; i<iteration;i++) {
3639
let p = RNFetchBlob
3740
.config({fileCache : true})
38-
.fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
39-
promises.push(p)
41+
.fetch('GET', `${TEST_SERVER_URL}/stress/${i}`)
42+
.then((res) => {
43+
finished ++
44+
let info = res.info()
45+
if(info.status == 200 && info.headers['Content-Length'] == '23975') {
46+
success ++
47+
}
48+
report(<Info key={`stress progress ${success}/${finished} tests successfully completed. size=${info.headers['Content-Length']} elapsed=${Date.now() - begin}ms`} uid="stress063"/>)
49+
fs.unlink(res.path()).catch(() => {})
50+
if(finished >= iteration)
51+
summary()
52+
})
53+
.catch((err) => {
54+
finished++
55+
report(<Info key={err} uid="stress063-err"/>)
56+
if(finished >= iteration){
57+
summary()
58+
}
59+
})
4060
}
41-
Promise.all(promises).then((resps) => {
42-
for(let i in resps) {
43-
fs.unlink(resps[i].path())
44-
}
45-
report(<Info key={`time = ${(Date.now() - begin) / 1000} sec`}></Info>)
61+
62+
function summary() {
63+
report(
64+
<Info key={`time = ${(Date.now() - begin) / 1000} sec`}>
65+
<Text>{`${success} success`}</Text>
66+
</Info>)
4667
done()
47-
})
68+
}
4869

4970
})

0 commit comments

Comments
 (0)