@@ -870,46 +870,53 @@ describe('BrowserMob Proxy Client general test', () => {
870
870
console . log ( value ) ;
871
871
done ( new Error ( value ) ) ; } ) ;
872
872
} ) ;
873
- it ( 'should setup latency to each HTTP request' , ( done ) => {
873
+ /*
874
+ skip - look here : https://github.com/lightbody/browsermob-proxy/issues/510
875
+ */
876
+ it . skip ( 'should setup latency to each HTTP request' , ( done ) => {
877
+
878
+ const upstreamKbps = 100 ;
879
+ const deltaInPercent = 1 ;
880
+ const enable = 'false' ;
874
881
875
- const latency = 1000 ;
876
- const deltaInPercent = 10 ;
877
- const limitsSetterObject = { latency : latency } ;
878
882
883
+ let limitsSetterObject = { upstreamKbps : upstreamKbps } ;
879
884
let browserMobProxyClient = undefined ;
880
885
881
886
( new bmpClient ( bmpHost , bmpPort ) ) . create ( )
882
887
. then ( ( client ) => {
883
888
browserMobProxyClient = client ;
884
889
return browserMobProxyClient . setLimits ( limitsSetterObject ) ;
885
890
} )
891
+ . then ( ( ) => {
892
+ limitsSetterObject = { enable : enable } ;
893
+ return browserMobProxyClient . setLimits ( limitsSetterObject ) ;
894
+ } )
886
895
. then ( ( ) => {
887
896
return browserMobProxyClient . newHar ( ) ;
888
897
} )
889
898
. then ( ( ) => {
890
- return request ( `${ moronHTTPUrl } ` ,
899
+ return request ( `${ moronHTTPUrl } /1MbitContent ` ,
891
900
{ method : 'GET' , proxy : `http://${ bmpHost } :${ browserMobProxyClient . port } ` } ) ;
892
901
} )
893
902
. then ( ( ) => {
894
903
return browserMobProxyClient . getHar ( ) ;
895
904
} )
896
905
. then ( ( har ) => {
906
+ console . log ( har . log . entries [ 0 ] . timings ) ;
907
+ const duration = har . log . entries [ 0 ] . timings . receive ;
908
+ const currentUpstreamSpeed = ( moronHTTP . oneMbitBuffer . length / 1024 ) / ( duration / 1000 ) ;
909
+ const currentDeltaInPercent = ( currentUpstreamSpeed > upstreamKbps ) ?
910
+ ( 100 - ( currentUpstreamSpeed - upstreamKbps ) / currentUpstreamSpeed * 100 )
911
+ : ( 100 - ( upstreamKbps - currentUpstreamSpeed ) / upstreamKbps * 100 ) ;
897
912
898
- const duration = har . log . entries [ 0 ] . timings . send ;
899
- const currentSpeed = ( moronHTTP . oneMbitBuffer . length / 1024 ) / ( duration / 1000 ) ;
900
-
901
- let currentDeltaInPercent = currentSpeed / latency * 100 - 100 ;
902
-
903
- if ( currentDeltaInPercent > deltaInPercent ) {
904
- currentDeltaInPercent = latency / currentSpeed * 100 - 100 ;
905
- if ( currentDeltaInPercent <= deltaInPercent ) {
906
- done ( ) ;
907
- } else {
908
- done ( new Error ( 'Delta between current latency speed and expected is too big' ) ) ;
909
- }
910
- } else {
913
+ console . log ( `duration : ${ duration / 1000 } , curentDeltaInPercent : ${ currentDeltaInPercent } %` ) ;
914
+ if ( currentDeltaInPercent <= deltaInPercent ) {
911
915
done ( ) ;
916
+ } else {
917
+ done ( new Error ( 'Delta between current upstream speed and expected is too big' ) ) ;
912
918
}
919
+
913
920
} )
914
921
. catch ( ( value ) => {
915
922
console . log ( value ) ;
0 commit comments