Nav apraksta

test-stress.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import RNTest from './react-native-testkit/'
  2. import React from 'react'
  3. import RNFetchBlob from 'react-native-fetch-blob'
  4. import Timer from 'react-timer-mixin'
  5. import {
  6. StyleSheet,
  7. Text,
  8. View,
  9. ScrollView,
  10. CameraRoll,
  11. Platform,
  12. Dimensions,
  13. Image,
  14. } from 'react-native';
  15. const fs = RNFetchBlob.fs
  16. const { Assert, Comparer, Info, prop } = RNTest
  17. const describe = RNTest.config({
  18. group : 'stress test',
  19. run : true,
  20. expand : true,
  21. timeout : 300000000,
  22. })
  23. const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, DROPBOX_TOKEN, styles } = prop()
  24. const dirs = RNFetchBlob.fs.dirs
  25. let prefix = ((Platform.OS === 'android') ? 'file://' : '')
  26. describe('massive HTTP request', (report, done) => {
  27. let promises = []
  28. let progress = []
  29. let iteration = 500
  30. let begin = Date.now()
  31. let finished = 0
  32. let success = 0
  33. for(let i=0; i<iteration;i++) {
  34. let p = RNFetchBlob
  35. .config({fileCache : true})
  36. .fetch('GET', `${TEST_SERVER_URL}/stress/${i}`)
  37. .then((res) => {
  38. finished ++
  39. let info = res.info()
  40. if(info.status == 200 && info.headers['Content-Length'] == '23975') {
  41. success ++
  42. }
  43. report(<Info key={`stress progress ${success}/${finished} tests successfully completed. size=${info.headers['Content-Length']} elapsed=${Date.now() - begin}ms`} uid="stress063"/>)
  44. fs.unlink(res.path()).catch(() => {})
  45. if(finished >= iteration)
  46. summary()
  47. })
  48. .catch((err) => {
  49. finished++
  50. report(<Info key={err} uid="stress063-err"/>)
  51. if(finished >= iteration){
  52. summary()
  53. }
  54. })
  55. }
  56. function summary() {
  57. report(
  58. <Info key={`time = ${(Date.now() - begin) / 1000} sec`}>
  59. <Text>{`${success} success`}</Text>
  60. </Info>)
  61. done()
  62. }
  63. })