Browse Source

Change stress test code

Ben Hsieh 8 years ago
parent
commit
646399f438
1 changed files with 30 additions and 9 deletions
  1. 30
    9
      test/test-0.6.3.js

+ 30
- 9
test/test-0.6.3.js View File

31
 
31
 
32
   let promises = []
32
   let promises = []
33
   let progress = []
33
   let progress = []
34
+  let iteration = 500
34
   let begin = Date.now()
35
   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++) {
36
     let p = RNFetchBlob
39
     let p = RNFetchBlob
37
     .config({fileCache : true})
40
     .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
+    })
40
   }
60
   }
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>)
46
     done()
67
     done()
47
-  })
68
+  }
48
 
69
 
49
 })
70
 })