diff options
author | cyBerta <cyberta@riseup.net> | 2021-11-23 12:34:00 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2021-11-23 12:34:00 +0100 |
commit | 829849c074d397ceba59c89fe4be0bd65ea49f6f (patch) | |
tree | d0236bf91d5303d24687f263633406d7d13980b6 /app/src/test/java/se/leap | |
parent | 9bf787465a3ae22c76249317496c8927b22ffdb4 (diff) |
calculate fake load from timezone distance if menshen doesn't serve load info
Diffstat (limited to 'app/src/test/java/se/leap')
-rw-r--r-- | app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java index 28311e18..33abfbed 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java @@ -70,6 +70,7 @@ public class GatewaysManagerTest { mockTextUtils(); when(ConfigHelper.getCurrentTimezone()).thenReturn(-1); when(ConfigHelper.stringEqual(anyString(), anyString())).thenCallRealMethod(); + when(ConfigHelper.getConnectionQualityFromTimezoneDistance(anyInt())).thenCallRealMethod(); when(ConfigHelper.isIPv4(anyString())).thenCallRealMethod(); when(ConfigHelper.timezoneDistance(anyInt(), anyInt())).thenCallRealMethod(); secrets = new JSONObject(getJsonStringFor("secrets.json")); @@ -400,6 +401,55 @@ public class GatewaysManagerTest { } + @Test + public void testGetLocations_noMenshen_obfs4_calculateAverageLoadFromTimezoneDistance() { + Provider provider = getProvider(null, null, null, null, null, null, "v4/riseup_eipservice_for_geoip_v4.json", "v4/riseup_geoip_v1.json"); + + MockHelper.mockProviderObservable(provider); + mockStatic(PreferenceHelper.class); + when(PreferenceHelper.getUseBridges(any(Context.class))).thenReturn(true); + sharedPreferences.edit().putBoolean(USE_BRIDGES, true).commit(); + GatewaysManager gatewaysManager = new GatewaysManager(mockContext); + List<Location> locations = gatewaysManager.getGatewayLocations(); + + assertEquals(3, locations.size()); + for (Location location : locations) { + if ("Montreal".equals(location.getName())) { + assertEquals(1, location.getNumberOfGateways(OBFS4)); + assertEquals(1/3.0, location.getAverageLoad(OBFS4)); + } + if ("Paris".equals(location.getName())) { + // checks that only gateways supporting obfs4 are taken into account + assertEquals(1, location.getNumberOfGateways(OBFS4)); + assertEquals(0.25, location.getAverageLoad(OBFS4)); + } + } + } + + @Test + public void testGetLocations_noMenshen_openvpn_calculateAverageLoadFromTimezoneDistance() { + Provider provider = getProvider(null, null, null, null, null, null, "v4/riseup_eipservice_for_geoip_v4.json", "v4/riseup_geoip_v1.json"); + + MockHelper.mockProviderObservable(provider); + mockStatic(PreferenceHelper.class); + when(PreferenceHelper.getUseBridges(any(Context.class))).thenReturn(false); + sharedPreferences.edit().putBoolean(USE_BRIDGES, false).commit(); + GatewaysManager gatewaysManager = new GatewaysManager(mockContext); + List<Location> locations = gatewaysManager.getGatewayLocations(); + + assertEquals(3, locations.size()); + for (Location location : locations) { + if ("Montreal".equals(location.getName())) { + assertEquals(1, location.getNumberOfGateways(OPENVPN)); + assertEquals(1/3.0, location.getAverageLoad(OPENVPN)); + } + if ("Paris".equals(location.getName())) { + // checks that only gateways supporting obfs4 are taken into account + assertEquals(3, location.getNumberOfGateways(OPENVPN)); + assertEquals(0.25, location.getAverageLoad(OPENVPN)); + } + } + } private String getJsonStringFor(String filename) throws IOException { return TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream(filename)); |