Browse Source

Add #140 test case and test server API

Ben Hsieh 8 years ago
parent
commit
2fb18c8130
2 changed files with 66 additions and 0 deletions
  1. 16
    0
      test-server/server.js
  2. 50
    0
      test/test-0.9.6.js

+ 16
- 0
test-server/server.js View File

166
   }, 5000)
166
   }, 5000)
167
 })
167
 })
168
 
168
 
169
+app.get('/10s-download', (req,res) => {
170
+  var count = 0
171
+  var data = ''
172
+  for(var i =0;i<1024000;i++)
173
+    data += '1'
174
+  res.set('Contet-Length', 1024000*10)
175
+  var it = setInterval(() => {
176
+    res.write(data)
177
+    count++
178
+    if(count == 10) {
179
+      clearInterval(it)
180
+      res.end()
181
+    }
182
+  }, 1000)
183
+})
184
+
169
 app.all('/long', (req, res) => {
185
 app.all('/long', (req, res) => {
170
   var count = 0;
186
   var count = 0;
171
   var it = setInterval(() => {
187
   var it = setInterval(() => {

+ 50
- 0
test/test-0.9.6.js View File

79
 })
79
 })
80
 
80
 
81
 describe('support download/upload progress interval and division #140 ', (report, done) => {
81
 describe('support download/upload progress interval and division #140 ', (report, done) => {
82
+  let tick = 0
83
+  let records = []
84
+  let last = Date.now()
85
+  RNFetchBlob.config({
86
+    timeout : 30000
87
+  }).fetch('GET', `${TEST_SERVER_URL}/10s-download`, {
88
+    'Cache-Control' : 'no-store'
89
+  })
90
+  .progress({interval : 1000},(current, total) => {
91
+    records.push(Date.now() - last)
92
+    last = Date.now()
93
+    console.log(current, '/', total, current/total)
94
+    tick ++
95
+  })
96
+  .then(() => {
97
+    let avg = 0
98
+    for(let i in records) {
99
+      avg+=records[i]
100
+    }
101
+    avg/=records.length
102
+    report(<Assert key="interval > 900" expect={900} comparer={Comparer.smaller} actual={avg}/>)
103
+    report(<Assert key="interval < 1200" expect={1200} comparer={Comparer.greater} actual={avg}/>)
104
+    upload()
105
+  })
106
+
107
+  function upload() {
108
+    let count = 0
109
+    let image = RNTest.prop('image')
110
+    RNFetchBlob.config({
111
+      fileCache : true
112
+    })
113
+    .fetch('GET', `${TEST_SERVER_URL}/public/6mb-dummy`)
114
+    .then((res) => {
115
+      return RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
116
+        Authorization : `Bearer ${DROPBOX_TOKEN}`,
117
+        'Dropbox-API-Arg': '{\"path\": \"/rn-upload/intervalTest.png\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
118
+        'Content-Type' : 'application/octet-stream',
119
+      }, RNFetchBlob.wrap(res.path()))
120
+      .uploadProgress({count : 10, interval : -1}, (current, total) => {
121
+        count++
122
+        console.log(current, total)
123
+      })
124
+    })
125
+    .then(() => {
126
+      report(<Assert key="count is correct" expect={10} actual={count}/>)
127
+      done()
128
+    })
129
+
130
+  }
131
+
82
 
132
 
83
 })
133
 })