2021-04-29 16:12:53 -04:00
/*! Unit tests that require access to the testing-only function
BridgeLine ::random ( ) or private fields * /
2023-03-27 12:36:57 -04:00
use super ::bridge_table ::{ BridgeLine , BRIDGE_BYTES } ;
2021-05-01 15:21:50 -04:00
use super ::proto ::* ;
2021-04-29 16:12:53 -04:00
use super ::* ;
2022-10-20 11:34:39 -04:00
use chrono ::{ DateTime , NaiveTime , Timelike , Utc } ;
2021-07-06 18:08:52 -04:00
use rand ::Rng ;
2021-06-15 02:01:24 -04:00
use statistical ::{ mean , standard_deviation } ;
2021-07-06 18:08:52 -04:00
use std ::collections ::HashSet ;
2022-04-03 01:03:35 -04:00
use std ::thread ;
2021-06-02 12:18:58 -04:00
use std ::time ::{ Duration , Instant } ;
2022-10-11 02:46:04 -04:00
#[ cfg(feature = " fast " ) ]
const USERS : usize = 100 ;
#[ cfg(not(feature = " fast " )) ]
const USERS : usize = 10000 ;
2021-06-02 12:18:58 -04:00
struct PerfStat {
// Report performance metrics for each test
req_len : usize ,
resp_len : usize ,
req_t : Duration ,
resp_t : Duration ,
resp_handle_t : Duration ,
}
2021-04-29 16:12:53 -04:00
2021-05-04 18:26:58 -04:00
struct TestHarness {
bdb : BridgeDb ,
pub ba : BridgeAuth ,
}
impl TestHarness {
fn new ( ) -> Self {
2021-06-15 02:01:24 -04:00
TestHarness ::new_buckets ( 5 , 5 )
}
2021-11-22 22:56:48 -05:00
fn new_buckets ( num_buckets : u16 , hot_spare : u16 ) -> Self {
2021-05-04 18:26:58 -04:00
// Create a BridegDb
2021-05-05 13:58:43 -04:00
let mut bdb = BridgeDb ::new ( ) ;
2021-05-04 18:26:58 -04:00
// Create a BridgeAuth
let mut ba = BridgeAuth ::new ( bdb . pubkey ) ;
2021-06-21 12:05:35 -04:00
// Make 3 x num_buckets open invitation bridges, in sets of 3
2021-06-15 02:01:24 -04:00
for _ in 0 .. num_buckets {
2021-05-05 13:58:43 -04:00
let bucket = [
BridgeLine ::random ( ) ,
BridgeLine ::random ( ) ,
BridgeLine ::random ( ) ,
] ;
ba . add_openinv_bridges ( bucket , & mut bdb ) ;
2021-05-04 18:26:58 -04:00
}
2021-06-21 12:05:35 -04:00
// Add hot_spare more hot spare buckets
2021-06-15 02:01:24 -04:00
for _ in 0 .. hot_spare {
2021-05-05 13:58:43 -04:00
let bucket = [
BridgeLine ::random ( ) ,
BridgeLine ::random ( ) ,
BridgeLine ::random ( ) ,
2021-05-04 18:26:58 -04:00
] ;
2021-05-05 13:58:43 -04:00
ba . add_spare_bucket ( bucket ) ;
2021-05-04 18:26:58 -04:00
}
// Create the encrypted bridge table
ba . enc_bridge_table ( ) ;
Self { bdb , ba }
2021-04-29 16:12:53 -04:00
}
2021-05-04 18:26:58 -04:00
fn advance_days ( & mut self , days : u16 ) {
self . ba . advance_days ( days ) ;
}
2021-04-29 16:12:53 -04:00
2021-06-02 12:18:58 -04:00
fn open_invite ( & mut self ) -> ( PerfStat , ( cred ::Lox , bridge_table ::BridgeLine ) ) {
2021-05-04 18:26:58 -04:00
// Issue an open invitation
let inv = self . bdb . invite ( ) ;
2021-04-29 16:12:53 -04:00
2021-06-02 12:18:58 -04:00
let req_start = Instant ::now ( ) ;
2021-05-04 18:26:58 -04:00
// Use it to get a Lox credential
let ( req , state ) = open_invite ::request ( & inv ) ;
2021-06-01 15:07:28 -04:00
let encoded : Vec < u8 > = bincode ::serialize ( & req ) . unwrap ( ) ;
2021-06-02 12:18:58 -04:00
let req_t = req_start . elapsed ( ) ;
2021-06-01 15:07:28 -04:00
let req_len = encoded . len ( ) ;
2021-06-02 12:18:58 -04:00
let resp_start = Instant ::now ( ) ;
2021-06-02 12:56:43 -04:00
let decoded = bincode ::deserialize ( & encoded [ .. ] ) . unwrap ( ) ;
2021-06-01 15:07:28 -04:00
let resp = self . ba . handle_open_invite ( decoded ) . unwrap ( ) ;
let encoded_resp : Vec < u8 > = bincode ::serialize ( & resp ) . unwrap ( ) ;
2021-06-02 12:18:58 -04:00
let resp_t = resp_start . elapsed ( ) ;
2021-06-01 15:07:28 -04:00
let resp_len = encoded_resp . len ( ) ;
2021-06-02 12:18:58 -04:00
let resp_handle_start = Instant ::now ( ) ;
2021-06-02 12:56:43 -04:00
let decode_resp = bincode ::deserialize ( & encoded_resp [ .. ] ) . unwrap ( ) ;
2021-06-02 12:18:58 -04:00
let ( cred , bridgeline ) =
open_invite ::handle_response ( state , decode_resp , & self . ba . lox_pub ) . unwrap ( ) ;
let resp_handle_t = resp_handle_start . elapsed ( ) ;
2021-07-06 18:08:52 -04:00
(
2021-06-02 12:18:58 -04:00
PerfStat {
req_len ,
resp_len ,
req_t ,
resp_t ,
resp_handle_t ,
} ,
( cred , bridgeline ) ,
2021-07-06 18:08:52 -04:00
)
2021-05-04 18:26:58 -04:00
}
2021-04-29 16:12:53 -04:00
2021-06-03 01:07:35 -04:00
fn trust_promotion ( & mut self , cred : & cred ::Lox ) -> ( PerfStat , cred ::Migration ) {
let req_start = Instant ::now ( ) ;
2021-05-04 18:26:58 -04:00
let ( promreq , promstate ) =
2022-10-18 00:51:17 -04:00
trust_promotion ::request ( cred , & self . ba . lox_pub , self . ba . today ( ) ) . unwrap ( ) ;
2021-06-03 01:07:35 -04:00
let encoded : Vec < u8 > = bincode ::serialize ( & promreq ) . unwrap ( ) ;
let req_t = req_start . elapsed ( ) ;
let req_len = encoded . len ( ) ;
let resp_start = Instant ::now ( ) ;
let decoded = bincode ::deserialize ( & encoded [ .. ] ) . unwrap ( ) ;
let promresp = self . ba . handle_trust_promotion ( decoded ) . unwrap ( ) ;
let encoded_resp : Vec < u8 > = bincode ::serialize ( & promresp ) . unwrap ( ) ;
let resp_t = resp_start . elapsed ( ) ;
let resp_len = encoded_resp . len ( ) ;
let resp_handle_start = Instant ::now ( ) ;
let decode_resp = bincode ::deserialize ( & encoded_resp [ .. ] ) . unwrap ( ) ;
let migcred = trust_promotion ::handle_response ( promstate , decode_resp ) . unwrap ( ) ;
let resp_handle_t = resp_handle_start . elapsed ( ) ;
2021-07-06 18:08:52 -04:00
(
2021-06-03 01:07:35 -04:00
PerfStat {
req_len ,
resp_len ,
req_t ,
resp_t ,
resp_handle_t ,
} ,
migcred ,
2021-07-06 18:08:52 -04:00
)
2021-04-29 16:12:53 -04:00
}
2021-05-04 18:26:58 -04:00
2021-06-03 01:07:35 -04:00
fn level0_migration (
& mut self ,
loxcred : & cred ::Lox ,
migcred : & cred ::Migration ,
) -> ( PerfStat , cred ::Lox ) {
let req_start = Instant ::now ( ) ;
2021-05-04 18:26:58 -04:00
let ( migreq , migstate ) =
migration ::request ( loxcred , migcred , & self . ba . lox_pub , & self . ba . migration_pub ) . unwrap ( ) ;
2021-06-03 01:07:35 -04:00
let encoded : Vec < u8 > = bincode ::serialize ( & migreq ) . unwrap ( ) ;
let req_t = req_start . elapsed ( ) ;
let req_len = encoded . len ( ) ;
let resp_start = Instant ::now ( ) ;
let decoded = bincode ::deserialize ( & encoded [ .. ] ) . unwrap ( ) ;
let migresp = self . ba . handle_migration ( decoded ) . unwrap ( ) ;
let encoded_resp : Vec < u8 > = bincode ::serialize ( & migresp ) . unwrap ( ) ;
let resp_t = resp_start . elapsed ( ) ;
let resp_len = encoded_resp . len ( ) ;
let resp_handle_start = Instant ::now ( ) ;
let decode_resp : migration ::Response = bincode ::deserialize ( & encoded_resp [ .. ] ) . unwrap ( ) ;
let cred = migration ::handle_response ( migstate , decode_resp , & self . ba . lox_pub ) . unwrap ( ) ;
let resp_handle_t = resp_handle_start . elapsed ( ) ;
2021-07-06 18:08:52 -04:00
(
2021-06-03 01:07:35 -04:00
PerfStat {
req_len ,
resp_len ,
req_t ,
resp_t ,
resp_handle_t ,
} ,
cred ,
2021-07-06 18:08:52 -04:00
)
2021-04-29 16:12:53 -04:00
}
2021-06-03 01:07:35 -04:00
fn level_up ( & mut self , cred : & cred ::Lox ) -> ( PerfStat , cred ::Lox ) {
2021-05-04 18:26:58 -04:00
// Read the bucket in the credential to get today's Bucket
// Reachability credential
2021-06-03 01:07:35 -04:00
2021-05-04 18:26:58 -04:00
let ( id , key ) = bridge_table ::from_scalar ( cred . bucket ) . unwrap ( ) ;
let encbuckets = self . ba . enc_bridge_table ( ) ;
let bucket =
bridge_table ::BridgeTable ::decrypt_bucket ( id , & key , & encbuckets [ id as usize ] ) . unwrap ( ) ;
let reachcred = bucket . 1. unwrap ( ) ;
// Use the Bucket Reachability credential to advance to the next
// level
2021-06-03 01:07:35 -04:00
let req_start = Instant ::now ( ) ;
2021-05-04 18:26:58 -04:00
let ( req , state ) = level_up ::request (
2022-10-18 00:51:17 -04:00
cred ,
2021-05-04 18:26:58 -04:00
& reachcred ,
& self . ba . lox_pub ,
& self . ba . reachability_pub ,
self . ba . today ( ) ,
)
. unwrap ( ) ;
2021-06-03 01:07:35 -04:00
let encoded : Vec < u8 > = bincode ::serialize ( & req ) . unwrap ( ) ;
let req_t = req_start . elapsed ( ) ;
let req_len = encoded . len ( ) ;
let resp_start = Instant ::now ( ) ;
let decoded = bincode ::deserialize ( & encoded [ .. ] ) . unwrap ( ) ;
let resp = self . ba . handle_level_up ( decoded ) . unwrap ( ) ;
let encoded_resp : Vec < u8 > = bincode ::serialize ( & resp ) . unwrap ( ) ;
let resp_t = resp_start . elapsed ( ) ;
let resp_len = encoded_resp . len ( ) ;
let resp_handle_start = Instant ::now ( ) ;
let decode_resp = bincode ::deserialize ( & encoded_resp [ .. ] ) . unwrap ( ) ;
let cred = level_up ::handle_response ( state , decode_resp , & self . ba . lox_pub ) . unwrap ( ) ;
let resp_handle_t = resp_handle_start . elapsed ( ) ;
2021-07-06 18:08:52 -04:00
(
2021-06-03 01:07:35 -04:00
PerfStat {
req_len ,
resp_len ,
req_t ,
resp_t ,
resp_handle_t ,
} ,
cred ,
2021-07-06 18:08:52 -04:00
)
2021-05-04 18:26:58 -04:00
}
2021-04-30 16:24:42 -04:00
2021-06-03 01:07:35 -04:00
fn issue_invite ( & mut self , cred : & cred ::Lox ) -> ( PerfStat , ( cred ::Lox , cred ::Invitation ) ) {
2021-05-04 18:26:58 -04:00
// Read the bucket in the credential to get today's Bucket
// Reachability credential
let ( id , key ) = bridge_table ::from_scalar ( cred . bucket ) . unwrap ( ) ;
let encbuckets = self . ba . enc_bridge_table ( ) ;
let bucket =
bridge_table ::BridgeTable ::decrypt_bucket ( id , & key , & encbuckets [ id as usize ] ) . unwrap ( ) ;
let reachcred = bucket . 1. unwrap ( ) ;
2021-06-03 01:07:35 -04:00
let req_start = Instant ::now ( ) ;
2021-05-04 18:26:58 -04:00
let ( req , state ) = issue_invite ::request (
2022-10-18 00:51:17 -04:00
cred ,
2021-05-04 18:26:58 -04:00
& reachcred ,
& self . ba . lox_pub ,
& self . ba . reachability_pub ,
self . ba . today ( ) ,
)
. unwrap ( ) ;
2021-06-03 01:07:35 -04:00
let encoded : Vec < u8 > = bincode ::serialize ( & req ) . unwrap ( ) ;
let req_t = req_start . elapsed ( ) ;
let req_len = encoded . len ( ) ;
let resp_start = Instant ::now ( ) ;
let decoded = bincode ::deserialize ( & encoded [ .. ] ) . unwrap ( ) ;
let resp = self . ba . handle_issue_invite ( decoded ) . unwrap ( ) ;
let encoded_resp : Vec < u8 > = bincode ::serialize ( & resp ) . unwrap ( ) ;
let resp_t = resp_start . elapsed ( ) ;
let resp_len = encoded_resp . len ( ) ;
let resp_handle_start = Instant ::now ( ) ;
let decode_resp = bincode ::deserialize ( & encoded_resp [ .. ] ) . unwrap ( ) ;
let ( cred , invite ) = issue_invite ::handle_response (
state ,
decode_resp ,
& self . ba . lox_pub ,
& self . ba . invitation_pub ,
)
. unwrap ( ) ;
let resp_handle_t = resp_handle_start . elapsed ( ) ;
2021-07-06 18:08:52 -04:00
(
2021-06-03 01:07:35 -04:00
PerfStat {
req_len ,
resp_len ,
req_t ,
resp_t ,
resp_handle_t ,
} ,
( cred , invite ) ,
2021-07-06 18:08:52 -04:00
)
2021-05-04 18:26:58 -04:00
}
2021-04-29 16:12:53 -04:00
2021-06-03 01:07:35 -04:00
fn redeem_invite ( & mut self , inv : & cred ::Invitation ) -> ( PerfStat , cred ::Lox ) {
let req_start = Instant ::now ( ) ;
2021-05-04 18:26:58 -04:00
let ( req , state ) =
2022-10-18 00:51:17 -04:00
redeem_invite ::request ( inv , & self . ba . invitation_pub , self . ba . today ( ) ) . unwrap ( ) ;
2021-06-03 01:07:35 -04:00
let encoded : Vec < u8 > = bincode ::serialize ( & req ) . unwrap ( ) ;
let req_t = req_start . elapsed ( ) ;
let req_len = encoded . len ( ) ;
let resp_start = Instant ::now ( ) ;
let decoded = bincode ::deserialize ( & encoded [ .. ] ) . unwrap ( ) ;
let resp = self . ba . handle_redeem_invite ( decoded ) . unwrap ( ) ;
let encoded_resp : Vec < u8 > = bincode ::serialize ( & resp ) . unwrap ( ) ;
let resp_t = resp_start . elapsed ( ) ;
let resp_len = encoded_resp . len ( ) ;
let resp_handle_start = Instant ::now ( ) ;
let decode_resp = bincode ::deserialize ( & encoded_resp [ .. ] ) . unwrap ( ) ;
let cred = redeem_invite ::handle_response ( state , decode_resp , & self . ba . lox_pub ) . unwrap ( ) ;
let resp_handle_t = resp_handle_start . elapsed ( ) ;
2021-07-06 18:08:52 -04:00
(
2021-06-03 01:07:35 -04:00
PerfStat {
req_len ,
resp_len ,
req_t ,
resp_t ,
resp_handle_t ,
} ,
cred ,
2021-07-06 18:08:52 -04:00
)
2021-05-04 18:26:58 -04:00
}
2021-05-05 16:28:56 -04:00
2021-06-03 01:07:35 -04:00
fn check_blockage ( & mut self , cred : & cred ::Lox ) -> ( PerfStat , cred ::Migration ) {
let req_start = Instant ::now ( ) ;
2022-10-18 00:51:17 -04:00
let ( req , state ) = check_blockage ::request ( cred , & self . ba . lox_pub ) . unwrap ( ) ;
2021-06-03 01:07:35 -04:00
let encoded : Vec < u8 > = bincode ::serialize ( & req ) . unwrap ( ) ;
let req_t = req_start . elapsed ( ) ;
let req_len = encoded . len ( ) ;
let resp_start = Instant ::now ( ) ;
let decoded = bincode ::deserialize ( & encoded [ .. ] ) . unwrap ( ) ;
let resp = self . ba . handle_check_blockage ( decoded ) . unwrap ( ) ;
let encoded_resp : Vec < u8 > = bincode ::serialize ( & resp ) . unwrap ( ) ;
let resp_t = resp_start . elapsed ( ) ;
let resp_len = encoded_resp . len ( ) ;
let resp_handle_start = Instant ::now ( ) ;
let decode_resp = bincode ::deserialize ( & encoded_resp [ .. ] ) . unwrap ( ) ;
let migcred = check_blockage ::handle_response ( state , decode_resp ) . unwrap ( ) ;
let resp_handle_t = resp_handle_start . elapsed ( ) ;
2021-07-06 18:08:52 -04:00
(
2021-06-03 01:07:35 -04:00
PerfStat {
req_len ,
resp_len ,
req_t ,
resp_t ,
resp_handle_t ,
} ,
migcred ,
2021-07-06 18:08:52 -04:00
)
2021-05-05 16:28:56 -04:00
}
2021-05-05 18:21:09 -04:00
2021-06-03 01:07:35 -04:00
fn blockage_migration (
& mut self ,
cred : & cred ::Lox ,
mig : & cred ::Migration ,
) -> ( PerfStat , cred ::Lox ) {
let req_start = Instant ::now ( ) ;
2021-05-05 18:21:09 -04:00
let ( req , state ) =
2022-10-18 00:51:17 -04:00
blockage_migration ::request ( cred , mig , & self . ba . lox_pub , & self . ba . migration_pub )
2021-05-05 18:21:09 -04:00
. unwrap ( ) ;
2021-06-03 01:07:35 -04:00
let encoded : Vec < u8 > = bincode ::serialize ( & req ) . unwrap ( ) ;
let req_t = req_start . elapsed ( ) ;
let req_len = encoded . len ( ) ;
let resp_start = Instant ::now ( ) ;
let decoded = bincode ::deserialize ( & encoded [ .. ] ) . unwrap ( ) ;
let resp = self . ba . handle_blockage_migration ( decoded ) . unwrap ( ) ;
let encoded_resp : Vec < u8 > = bincode ::serialize ( & resp ) . unwrap ( ) ;
let resp_t = resp_start . elapsed ( ) ;
let resp_len = encoded_resp . len ( ) ;
let resp_handle_start = Instant ::now ( ) ;
let decode_resp : blockage_migration ::Response =
bincode ::deserialize ( & encoded_resp [ .. ] ) . unwrap ( ) ;
let cred =
blockage_migration ::handle_response ( state , decode_resp , & self . ba . lox_pub ) . unwrap ( ) ;
let resp_handle_t = resp_handle_start . elapsed ( ) ;
2021-07-06 18:08:52 -04:00
(
2021-06-03 01:07:35 -04:00
PerfStat {
req_len ,
resp_len ,
req_t ,
resp_t ,
resp_handle_t ,
} ,
cred ,
2021-07-06 18:08:52 -04:00
)
2021-05-05 18:21:09 -04:00
}
2021-05-04 18:26:58 -04:00
}
2021-04-29 16:12:53 -04:00
2022-04-03 01:54:53 -04:00
#[ test ]
2021-05-04 18:26:58 -04:00
fn test_open_invite ( ) {
let mut th = TestHarness ::new ( ) ;
2021-04-29 18:22:06 -04:00
2021-05-04 18:26:58 -04:00
// Join an untrusted user
2021-06-02 12:18:58 -04:00
let ( perf_stat , ( cred , bridgeline ) ) = th . open_invite ( ) ;
2021-04-30 16:24:42 -04:00
2021-05-04 18:26:58 -04:00
// Check that we can use the credential to read a bucket
let ( id , key ) = bridge_table ::from_scalar ( cred . bucket ) . unwrap ( ) ;
let encbuckets = th . ba . enc_bridge_table ( ) ;
let bucket =
bridge_table ::BridgeTable ::decrypt_bucket ( id , & key , & encbuckets [ id as usize ] ) . unwrap ( ) ;
2021-06-22 14:43:15 -04:00
print_test_results ( perf_stat ) ;
2021-05-04 18:26:58 -04:00
println! ( " cred = {:?} " , cred ) ;
println! ( " bucket = {:?} " , bucket ) ;
2021-05-18 14:46:35 -04:00
println! ( " bridgeline = {:?} " , bridgeline ) ;
2021-05-04 18:26:58 -04:00
assert! ( bucket . 1. is_none ( ) ) ;
assert! ( th . ba . verify_lox ( & cred ) ) ;
2021-05-18 14:46:35 -04:00
assert! ( bridgeline = = bucket . 0 [ 0 ] ) ;
2021-04-30 16:24:42 -04:00
}
2022-04-03 01:54:53 -04:00
#[ test ]
2021-04-30 16:24:42 -04:00
fn test_trust_promotion ( ) {
2021-05-04 18:26:58 -04:00
let mut th = TestHarness ::new ( ) ;
2021-04-30 16:24:42 -04:00
2021-06-02 12:18:58 -04:00
let cred = th . open_invite ( ) . 1 . 0 ;
2021-05-04 18:26:58 -04:00
assert! ( th . ba . verify_lox ( & cred ) ) ;
// Time passes
th . advance_days ( 47 ) ;
2021-06-03 01:07:35 -04:00
let ( perf_stat , migcred ) = th . trust_promotion ( & cred ) ;
2021-05-04 18:26:58 -04:00
assert! ( th . ba . verify_migration ( & migcred ) ) ;
2021-04-30 16:24:42 -04:00
2021-04-30 13:30:20 -04:00
// Check that we can use the to_bucket in the Migration credenital
// to read a bucket
let ( id , key ) = bridge_table ::from_scalar ( migcred . to_bucket ) . unwrap ( ) ;
2021-05-04 18:26:58 -04:00
let encbuckets = th . ba . enc_bridge_table ( ) ;
2021-05-01 17:12:03 -04:00
let bucket =
bridge_table ::BridgeTable ::decrypt_bucket ( id , & key , & encbuckets [ id as usize ] ) . unwrap ( ) ;
2021-06-22 14:43:15 -04:00
print_test_results ( perf_stat ) ;
2021-04-30 13:30:20 -04:00
println! ( " bucket = {:?} " , bucket ) ;
2021-05-04 18:26:58 -04:00
assert! ( th . ba . verify_reachability ( & bucket . 1. unwrap ( ) ) ) ;
2021-05-01 22:25:32 -04:00
}
2022-04-03 01:54:53 -04:00
#[ test ]
2021-05-01 22:25:32 -04:00
fn test_level0_migration ( ) {
2021-05-04 18:26:58 -04:00
let mut th = TestHarness ::new ( ) ;
2021-06-02 12:18:58 -04:00
let cred = th . open_invite ( ) . 1 . 0 ;
2021-05-04 18:26:58 -04:00
assert! ( th . ba . verify_lox ( & cred ) ) ;
// Time passes
th . advance_days ( 47 ) ;
2021-05-01 22:25:32 -04:00
2021-06-03 01:07:35 -04:00
let ( perf_stat , migcred ) = th . trust_promotion ( & cred ) ;
2021-05-04 18:26:58 -04:00
assert! ( th . ba . verify_migration ( & migcred ) ) ;
2021-06-22 14:43:15 -04:00
println! ( " --Trust Promotion to 1-- \n " ) ;
print_test_results ( perf_stat ) ;
2021-06-03 01:07:35 -04:00
let ( mperf_stat , newloxcred ) = th . level0_migration ( & cred , & migcred ) ;
2021-06-22 14:43:15 -04:00
println! ( " --Level 0 migration-- \n " ) ;
print_test_results ( mperf_stat ) ;
2021-05-04 18:26:58 -04:00
assert! ( th . ba . verify_lox ( & newloxcred ) ) ;
2021-04-30 16:24:42 -04:00
println! ( " newloxcred = {:?} " , newloxcred ) ;
// Check that we can use the credenital to read a bucket
let ( id , key ) = bridge_table ::from_scalar ( newloxcred . bucket ) . unwrap ( ) ;
2021-05-04 18:26:58 -04:00
let encbuckets = th . ba . enc_bridge_table ( ) ;
2021-05-01 17:12:03 -04:00
let bucket =
bridge_table ::BridgeTable ::decrypt_bucket ( id , & key , & encbuckets [ id as usize ] ) . unwrap ( ) ;
2021-04-30 16:24:42 -04:00
println! ( " bucket = {:?} " , bucket ) ;
2021-05-04 18:26:58 -04:00
assert! ( th . ba . verify_reachability ( & bucket . 1. unwrap ( ) ) ) ;
2021-05-02 21:44:33 -04:00
}
2022-04-03 01:54:53 -04:00
#[ test ]
2021-05-02 21:44:33 -04:00
fn test_level_up ( ) {
2021-05-04 18:26:58 -04:00
let mut th = TestHarness ::new ( ) ;
// Join an untrusted user
2021-06-02 12:18:58 -04:00
let cred = th . open_invite ( ) . 1 . 0 ;
2021-05-04 18:26:58 -04:00
// Time passes
th . advance_days ( 47 ) ;
// Go up to level 1
2021-06-03 01:07:35 -04:00
let ( perf_stat , migcred ) = th . trust_promotion ( & cred ) ;
2021-06-22 14:43:15 -04:00
println! ( " --Trust Promotion to 1-- \n " ) ;
print_test_results ( perf_stat ) ;
2021-06-03 01:07:35 -04:00
let ( mperf_stat , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
2021-06-22 14:43:15 -04:00
println! ( " --New Level 1 Credential-- \n " ) ;
print_test_results ( mperf_stat ) ;
2021-06-03 01:07:35 -04:00
2021-05-02 21:44:33 -04:00
assert! ( scalar_u32 ( & cred1 . trust_level ) . unwrap ( ) = = 1 ) ;
// Time passes
2021-05-04 18:26:58 -04:00
th . advance_days ( 20 ) ;
2021-05-02 21:44:33 -04:00
2021-06-03 01:07:35 -04:00
let ( two_perf_stat , cred2 ) = th . level_up ( & cred1 ) ;
2021-05-02 21:44:33 -04:00
assert! ( scalar_u32 ( & cred2 . trust_level ) . unwrap ( ) = = 2 ) ;
2021-06-22 14:43:15 -04:00
println! ( " --Upgrade to Level 2-- \n " ) ;
print_test_results ( two_perf_stat ) ;
2021-05-02 21:44:33 -04:00
println! ( " cred2 = {:?} " , cred2 ) ;
2021-05-04 18:26:58 -04:00
assert! ( th . ba . verify_lox ( & cred2 ) ) ;
2021-05-02 21:44:33 -04:00
// Time passes
2021-05-04 18:26:58 -04:00
th . advance_days ( 30 ) ;
2021-05-02 21:44:33 -04:00
2021-06-03 01:07:35 -04:00
let ( three_perf_stat , cred3 ) = th . level_up ( & cred2 ) ;
2021-05-02 21:44:33 -04:00
assert! ( scalar_u32 ( & cred3 . trust_level ) . unwrap ( ) = = 3 ) ;
2021-06-22 14:43:15 -04:00
println! ( " --Upgrade to Level 3-- \n " ) ;
print_test_results ( three_perf_stat ) ;
2021-05-02 21:44:33 -04:00
println! ( " cred3 = {:?} " , cred3 ) ;
2021-05-04 18:26:58 -04:00
assert! ( th . ba . verify_lox ( & cred3 ) ) ;
2021-05-02 21:44:33 -04:00
// Time passes
2021-05-04 18:26:58 -04:00
th . advance_days ( 60 ) ;
2021-05-02 21:44:33 -04:00
2021-06-03 01:07:35 -04:00
let ( four_perf_stat , cred4 ) = th . level_up ( & cred3 ) ;
2021-05-02 21:44:33 -04:00
assert! ( scalar_u32 ( & cred3 . trust_level ) . unwrap ( ) = = 3 ) ;
2021-06-22 14:43:15 -04:00
println! ( " --Upgrade to Level 4-- \n " ) ;
print_test_results ( four_perf_stat ) ;
2021-05-02 21:44:33 -04:00
println! ( " cred4 = {:?} " , cred4 ) ;
2021-05-04 18:26:58 -04:00
assert! ( th . ba . verify_lox ( & cred4 ) ) ;
2021-05-04 15:47:37 -04:00
}
2022-04-03 01:54:53 -04:00
#[ test ]
2021-05-04 15:47:37 -04:00
fn test_issue_invite ( ) {
2021-05-04 18:26:58 -04:00
let mut th = TestHarness ::new ( ) ;
// Join an untrusted user
2021-06-02 12:18:58 -04:00
let cred = th . open_invite ( ) . 1 . 0 ;
2021-05-04 18:26:58 -04:00
// Time passes
th . advance_days ( 47 ) ;
// Go up to level 1
2021-06-22 14:43:15 -04:00
let ( perf_stat , migcred ) = th . trust_promotion ( & cred ) ;
println! ( " --Trust Promotion to 1-- \n " ) ;
print_test_results ( perf_stat ) ;
let ( mperf_stat , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
println! ( " --New Level 1 Credential-- \n " ) ;
print_test_results ( mperf_stat ) ;
2021-05-04 15:47:37 -04:00
assert! ( scalar_u32 ( & cred1 . trust_level ) . unwrap ( ) = = 1 ) ;
// Time passes
2021-05-04 18:26:58 -04:00
th . advance_days ( 20 ) ;
2021-05-04 15:47:37 -04:00
2021-05-04 18:26:58 -04:00
// Go up to level 2
2021-06-22 14:43:15 -04:00
let ( two_perf_stat , cred2 ) = th . level_up ( & cred1 ) ;
println! ( " --Upgrade to Level 2-- \n " ) ;
print_test_results ( two_perf_stat ) ;
2021-05-04 15:47:37 -04:00
assert! ( scalar_u32 ( & cred2 . trust_level ) . unwrap ( ) = = 2 ) ;
println! ( " cred2 = {:?} " , cred2 ) ;
2021-05-04 18:26:58 -04:00
assert! ( th . ba . verify_lox ( & cred2 ) ) ;
2021-05-04 15:47:37 -04:00
2021-05-04 18:26:58 -04:00
// Issue an invitation
2021-06-22 14:43:15 -04:00
let ( invite_perf_stat , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
println! ( " --Issue Invitation-- \n " ) ;
print_test_results ( invite_perf_stat ) ;
2021-05-04 18:26:58 -04:00
assert! ( th . ba . verify_lox ( & cred2a ) ) ;
assert! ( th . ba . verify_invitation ( & invite ) ) ;
println! ( " cred2a = {:?} " , cred2a ) ;
2021-05-04 14:21:38 -04:00
println! ( " invite = {:?} " , invite ) ;
2021-05-03 19:05:42 -04:00
}
2021-05-04 15:47:37 -04:00
2022-04-03 01:54:53 -04:00
#[ test ]
2021-05-04 15:47:37 -04:00
fn test_redeem_invite ( ) {
2021-05-04 18:26:58 -04:00
let mut th = TestHarness ::new ( ) ;
// Join an untrusted user
2021-06-02 12:18:58 -04:00
let cred = th . open_invite ( ) . 1 . 0 ;
2021-05-04 18:26:58 -04:00
// Time passes
th . advance_days ( 47 ) ;
// Go up to level 1
2021-06-22 14:43:15 -04:00
let ( perf_stat , migcred ) = th . trust_promotion ( & cred ) ;
println! ( " --Trust Promotion to 1-- \n " ) ;
print_test_results ( perf_stat ) ;
let ( mperf_stat , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
println! ( " --New Level 1 Credential-- \n " ) ;
print_test_results ( mperf_stat ) ;
2021-05-04 15:47:37 -04:00
assert! ( scalar_u32 ( & cred1 . trust_level ) . unwrap ( ) = = 1 ) ;
// Time passes
2021-05-04 18:26:58 -04:00
th . advance_days ( 20 ) ;
2021-05-04 15:47:37 -04:00
2021-05-04 18:26:58 -04:00
// Go up to level 2
2021-06-22 14:43:15 -04:00
let ( two_perf_stat , cred2 ) = th . level_up ( & cred1 ) ;
println! ( " --Upgrade to Level 2-- \n " ) ;
print_test_results ( two_perf_stat ) ;
2021-05-04 15:47:37 -04:00
assert! ( scalar_u32 ( & cred2 . trust_level ) . unwrap ( ) = = 2 ) ;
println! ( " cred2 = {:?} " , cred2 ) ;
2021-05-04 18:26:58 -04:00
assert! ( th . ba . verify_lox ( & cred2 ) ) ;
2021-05-04 15:47:37 -04:00
2021-05-04 18:26:58 -04:00
// Issue an invitation to Bob
2021-06-22 14:43:15 -04:00
let ( invite_perf_stat , ( cred2a , bob_invite ) ) = th . issue_invite ( & cred2 ) ;
println! ( " --Issue Invitation-- \n " ) ;
print_test_results ( invite_perf_stat ) ;
2021-05-04 18:26:58 -04:00
assert! ( th . ba . verify_lox ( & cred2a ) ) ;
assert! ( th . ba . verify_invitation ( & bob_invite ) ) ;
println! ( " cred2a = {:?} " , cred2a ) ;
println! ( " bob_invite = {:?} " , bob_invite ) ;
2021-05-04 15:47:37 -04:00
2021-05-04 17:48:15 -04:00
// Time passes
2021-05-04 18:26:58 -04:00
th . advance_days ( 12 ) ;
2021-05-04 17:48:15 -04:00
2021-05-04 18:26:58 -04:00
// Bob joins the system
2021-06-22 14:43:15 -04:00
let ( bob_perf_stat , bob_cred ) = th . redeem_invite ( & bob_invite ) ;
println! ( " --Bob joins the system-- \n " ) ;
print_test_results ( bob_perf_stat ) ;
2021-05-04 18:26:58 -04:00
assert! ( th . ba . verify_lox ( & bob_cred ) ) ;
println! ( " bob_cred = {:?} " , bob_cred ) ;
2021-05-04 15:47:37 -04:00
}
2021-05-05 13:58:43 -04:00
2023-03-27 12:36:57 -04:00
#[ test ]
fn test_update_bridge ( ) {
let mut th = TestHarness ::new ( ) ;
// Add new bridge to table with known values,
// check that I can find and update the values and that everything else stays the same
// Create 3 bridges to test harness
let bucket = [
BridgeLine ::random ( ) ,
BridgeLine ::random ( ) ,
BridgeLine ::random ( ) ,
] ;
// Store first bridgeline to update later
let bridgeline_to_update = bucket [ 0 ] ;
// Created changed info for bridgeline to be updated to
let updated_info = bucket [ 0 ] ;
let infostr : String = format! (
" type={} blocked_in={:?} protocol={} fingerprint={} distribution={} " ,
" obfs2 test bridge " . to_string ( ) ,
{ } ,
" obfs2 " . to_string ( ) ,
" ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCD " . to_string ( ) ,
" moat " . to_string ( ) ,
) ;
let mut updated_info_bytes : [ u8 ; BRIDGE_BYTES - 18 ] = [ 0 ; BRIDGE_BYTES - 18 ] ;
updated_info_bytes [ .. infostr . len ( ) ] . copy_from_slice ( infostr . as_bytes ( ) ) ;
let updated_bridgeline = BridgeLine {
addr : bridgeline_to_update . addr ,
port : bridgeline_to_update . port ,
info : updated_info_bytes ,
} ;
assert! (
updated_bridgeline . addr = = bridgeline_to_update . addr ,
" Bridge entering the bridgepool {:?} did not have the same IP as the updating bridge {:?} " ,
bridgeline_to_update ,
updated_bridgeline . addr
) ;
assert! ( updated_bridgeline . port = = bridgeline_to_update . port , " Bridge entering the bridgepool {:?} did not have the same port as the updating bridge {:?} " , bridgeline_to_update , updated_bridgeline . port ) ;
assert! ( updated_bridgeline . info ! = bridgeline_to_update . info ) ;
println! (
" Bridge entering the bridgepool {:?} has different info than the updating bridge {:?} " ,
bridgeline_to_update . info , updated_bridgeline . info
) ;
assert! ( updated_bridgeline ! = bridgeline_to_update ) ;
println! ( " The two bridgelines are not equal before the update " ) ;
// Add 3 bridges to test harness
th . ba . add_openinv_bridges ( bucket , & mut th . bdb ) ;
println! ( " Before update spares = {:?} " , th . ba . bridge_table . spares ) ;
println! (
" Before update tmig = {:?} " ,
th . ba . trustup_migration_table . table
) ;
println! (
" Before update bmig = {:?} " ,
th . ba . blockage_migration_table . table
) ;
println! ( " Before update openinv = {:?} \n " , th . bdb . openinv_buckets ) ;
// Update the info of a bridge with matching IP and Port to a bridge in the bridge table
let result = th . ba . bridge_update ( & updated_bridgeline ) ;
assert! ( result , " Bridge failed to update successfully!! " ) ;
let found_bridge = th
. ba
. bridge_table
. reachable
. get_key_value ( & updated_bridgeline ) ;
assert! ( * found_bridge . unwrap ( ) . 0 ! = bridgeline_to_update ) ;
assert! ( * found_bridge . unwrap ( ) . 0 = = updated_bridgeline ) ;
println! ( " After update spares = {:?} " , th . ba . bridge_table . spares ) ;
println! (
" After update tmig = {:?} " ,
th . ba . trustup_migration_table . table
) ;
println! (
" After update bmig = {:?} " ,
th . ba . blockage_migration_table . table
) ;
println! ( " After update openinv = {:?} \n " , th . bdb . openinv_buckets ) ;
}
2022-04-03 01:54:53 -04:00
#[ test ]
2021-05-05 13:58:43 -04:00
fn test_mark_unreachable ( ) {
let mut th = TestHarness ::new ( ) ;
println! ( " spares = {:?} " , th . ba . bridge_table . spares ) ;
println! ( " tmig = {:?} " , th . ba . trustup_migration_table . table ) ;
println! ( " bmig = {:?} " , th . ba . blockage_migration_table . table ) ;
println! ( " openinv = {:?} \n " , th . bdb . openinv_buckets ) ;
// Mark a bridge in an untrusted bucket as unreachable
let b6 = th . ba . bridge_table . buckets [ 6 ] [ 0 ] ;
th . ba . bridge_unreachable ( & b6 , & mut th . bdb ) ;
println! ( " spares = {:?} " , th . ba . bridge_table . spares ) ;
println! ( " tmig = {:?} " , th . ba . trustup_migration_table . table ) ;
println! ( " bmig = {:?} " , th . ba . blockage_migration_table . table ) ;
println! ( " openinv = {:?} \n " , th . bdb . openinv_buckets ) ;
// Mark another bridge grouped to the same trusted bucket as
// unreachable
let b7 = th . ba . bridge_table . buckets [ 7 ] [ 0 ] ;
th . ba . bridge_unreachable ( & b7 , & mut th . bdb ) ;
println! ( " spares = {:?} " , th . ba . bridge_table . spares ) ;
println! ( " tmig = {:?} " , th . ba . trustup_migration_table . table ) ;
println! ( " bmig = {:?} " , th . ba . blockage_migration_table . table ) ;
println! ( " openinv = {:?} \n " , th . bdb . openinv_buckets ) ;
// That will have introduced a blockage migration. Get the target
let target : u32 = * th
. ba
. blockage_migration_table
. table
. iter ( )
. next ( )
. unwrap ( )
. 1 ;
// Block two of the bridges in that target bucket
let bt1 = th . ba . bridge_table . buckets [ target as usize ] [ 1 ] ;
let bt2 = th . ba . bridge_table . buckets [ target as usize ] [ 2 ] ;
th . ba . bridge_unreachable ( & bt1 , & mut th . bdb ) ;
th . ba . bridge_unreachable ( & bt2 , & mut th . bdb ) ;
println! ( " spares = {:?} " , th . ba . bridge_table . spares ) ;
println! ( " tmig = {:?} " , th . ba . trustup_migration_table . table ) ;
println! ( " bmig = {:?} " , th . ba . blockage_migration_table . table ) ;
println! ( " openinv = {:?} \n " , th . bdb . openinv_buckets ) ;
}
2021-05-05 16:28:56 -04:00
2022-04-03 01:54:53 -04:00
#[ test ]
2021-05-05 18:21:09 -04:00
fn test_blockage_migration ( ) {
2021-05-05 16:28:56 -04:00
let mut th = TestHarness ::new ( ) ;
// Join an untrusted user
2021-06-02 12:18:58 -04:00
let cred = th . open_invite ( ) . 1 . 0 ;
2021-05-05 16:28:56 -04:00
// Time passes
th . advance_days ( 47 ) ;
// Go up to level 1
2021-06-15 02:01:24 -04:00
let ( _mperf_stat , migcred ) = th . trust_promotion ( & cred ) ;
let ( _perf_stat , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
2021-05-05 16:28:56 -04:00
assert! ( scalar_u32 ( & cred1 . trust_level ) . unwrap ( ) = = 1 ) ;
// Time passes
th . advance_days ( 20 ) ;
// Go up to level 2
2021-06-15 02:01:24 -04:00
let ( _two_perf_stat , cred2 ) = th . level_up ( & cred1 ) ;
2021-05-05 16:28:56 -04:00
assert! ( scalar_u32 ( & cred2 . trust_level ) . unwrap ( ) = = 2 ) ;
println! ( " cred2 = {:?} " , cred2 ) ;
assert! ( th . ba . verify_lox ( & cred2 ) ) ;
// Time passes
th . advance_days ( 29 ) ;
// Go up to level 3
2021-06-15 02:01:24 -04:00
let ( _three_perf_stat , cred3 ) = th . level_up ( & cred2 ) ;
2021-05-05 16:28:56 -04:00
assert! ( scalar_u32 ( & cred3 . trust_level ) . unwrap ( ) = = 3 ) ;
println! ( " cred3 = {:?} " , cred3 ) ;
assert! ( th . ba . verify_lox ( & cred3 ) ) ;
// Get our bridges
let ( id , key ) = bridge_table ::from_scalar ( cred3 . bucket ) . unwrap ( ) ;
let encbuckets = th . ba . enc_bridge_table ( ) ;
let bucket =
bridge_table ::BridgeTable ::decrypt_bucket ( id , & key , & encbuckets [ id as usize ] ) . unwrap ( ) ;
// We should have a Bridge Reachability credential
assert! ( bucket . 1. is_some ( ) ) ;
// Oh, no! Two of our bridges are blocked!
th . ba . bridge_unreachable ( & bucket . 0 [ 0 ] , & mut th . bdb ) ;
th . ba . bridge_unreachable ( & bucket . 0 [ 2 ] , & mut th . bdb ) ;
println! ( " spares = {:?} " , th . ba . bridge_table . spares ) ;
println! ( " tmig = {:?} " , th . ba . trustup_migration_table . table ) ;
println! ( " bmig = {:?} " , th . ba . blockage_migration_table . table ) ;
println! ( " openinv = {:?} \n " , th . bdb . openinv_buckets ) ;
// Time passes
th . advance_days ( 1 ) ;
let encbuckets2 = th . ba . enc_bridge_table ( ) ;
let bucket2 =
bridge_table ::BridgeTable ::decrypt_bucket ( id , & key , & encbuckets2 [ id as usize ] ) . unwrap ( ) ;
// We should no longer have a Bridge Reachability credential
assert! ( bucket2 . 1. is_none ( ) ) ;
// See about getting a Migration credential for the blockage
2021-06-15 02:01:24 -04:00
let ( _block_perf_stat , migration ) = th . check_blockage ( & cred3 ) ;
2021-05-05 16:28:56 -04:00
println! ( " migration = {:?} " , migration ) ;
2021-05-05 18:21:09 -04:00
// Migrate
2021-06-15 02:01:24 -04:00
let ( _four_perf_stat , cred4 ) = th . blockage_migration ( & cred3 , & migration ) ;
2021-05-05 18:21:09 -04:00
println! ( " cred4 = {:?} " , cred4 ) ;
assert! ( th . ba . verify_lox ( & cred4 ) ) ;
2021-05-05 16:28:56 -04:00
}
2021-06-15 02:01:24 -04:00
2022-04-03 01:54:53 -04:00
#[ test ]
2021-11-23 12:02:34 -05:00
fn stats_test_trust_levels ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-07-18 18:51:49 -04:00
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut promo_req_size : Vec < f64 > = Vec ::new ( ) ;
let mut promo_resp_size : Vec < f64 > = Vec ::new ( ) ;
let mut promo_req_time : Vec < f64 > = Vec ::new ( ) ;
let mut promo_resp_time : Vec < f64 > = Vec ::new ( ) ;
let mut promo_resp_handle_time : Vec < f64 > = Vec ::new ( ) ;
let mut mig_req_size : Vec < f64 > = Vec ::new ( ) ;
let mut mig_resp_size : Vec < f64 > = Vec ::new ( ) ;
let mut mig_req_time : Vec < f64 > = Vec ::new ( ) ;
let mut mig_resp_time : Vec < f64 > = Vec ::new ( ) ;
let mut mig_resp_handle_time : Vec < f64 > = Vec ::new ( ) ;
let mut sec_req_size : Vec < f64 > = Vec ::new ( ) ;
let mut sec_resp_size : Vec < f64 > = Vec ::new ( ) ;
let mut sec_req_time : Vec < f64 > = Vec ::new ( ) ;
let mut sec_resp_time : Vec < f64 > = Vec ::new ( ) ;
let mut sec_resp_handle_time : Vec < f64 > = Vec ::new ( ) ;
let mut three_req_size : Vec < f64 > = Vec ::new ( ) ;
let mut three_resp_size : Vec < f64 > = Vec ::new ( ) ;
let mut three_req_time : Vec < f64 > = Vec ::new ( ) ;
let mut three_resp_time : Vec < f64 > = Vec ::new ( ) ;
let mut three_resp_handle_time : Vec < f64 > = Vec ::new ( ) ;
let mut four_req_size : Vec < f64 > = Vec ::new ( ) ;
let mut four_resp_size : Vec < f64 > = Vec ::new ( ) ;
let mut four_req_time : Vec < f64 > = Vec ::new ( ) ;
let mut four_resp_time : Vec < f64 > = Vec ::new ( ) ;
let mut four_resp_handle_time : Vec < f64 > = Vec ::new ( ) ;
let mut open_req_size : Vec < f64 > = Vec ::new ( ) ;
let mut open_resp_size : Vec < f64 > = Vec ::new ( ) ;
let mut open_req_time : Vec < f64 > = Vec ::new ( ) ;
let mut open_resp_time : Vec < f64 > = Vec ::new ( ) ;
let mut open_resp_handle_time : Vec < f64 > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-22 22:56:48 -05:00
let ( open_perf_stat , cred ) = th . open_invite ( ) ;
th . advance_days ( 30 ) ;
let ( tp_perf_stat , migcred ) = th . trust_promotion ( & cred . 0 ) ;
let ( mig_perf_stat , cred1 ) = th . level0_migration ( & cred . 0 , & migcred ) ;
th . advance_days ( 14 ) ;
let ( sec_perf_stat , cred2 ) = th . level_up ( & cred1 ) ;
th . advance_days ( 28 ) ;
2021-11-23 12:02:34 -05:00
let ( three_perf_stat , cred3 ) = th . level_up ( & cred2 ) ;
2021-11-22 22:56:48 -05:00
th . advance_days ( 56 ) ;
2021-11-23 12:02:34 -05:00
let ( four_perf_stat , _ ) = th . level_up ( & cred3 ) ;
2021-11-22 22:56:48 -05:00
open_req_size . push ( open_perf_stat . req_len as f64 ) ;
open_req_time . push ( open_perf_stat . req_t . as_secs_f64 ( ) ) ;
open_resp_size . push ( open_perf_stat . resp_len as f64 ) ;
open_resp_time . push ( open_perf_stat . resp_t . as_secs_f64 ( ) ) ;
open_resp_handle_time . push ( open_perf_stat . resp_handle_t . as_secs_f64 ( ) ) ;
promo_req_size . push ( tp_perf_stat . req_len as f64 ) ;
promo_req_time . push ( tp_perf_stat . req_t . as_secs_f64 ( ) ) ;
promo_resp_size . push ( tp_perf_stat . resp_len as f64 ) ;
promo_resp_time . push ( tp_perf_stat . resp_t . as_secs_f64 ( ) ) ;
promo_resp_handle_time . push ( tp_perf_stat . resp_handle_t . as_secs_f64 ( ) ) ;
mig_req_size . push ( mig_perf_stat . req_len as f64 ) ;
mig_req_time . push ( mig_perf_stat . req_t . as_secs_f64 ( ) ) ;
mig_resp_size . push ( mig_perf_stat . resp_len as f64 ) ;
mig_resp_time . push ( mig_perf_stat . resp_t . as_secs_f64 ( ) ) ;
mig_resp_handle_time . push ( mig_perf_stat . resp_handle_t . as_secs_f64 ( ) ) ;
sec_req_size . push ( sec_perf_stat . req_len as f64 ) ;
sec_req_time . push ( sec_perf_stat . req_t . as_secs_f64 ( ) ) ;
sec_resp_size . push ( sec_perf_stat . resp_len as f64 ) ;
sec_resp_time . push ( sec_perf_stat . resp_t . as_secs_f64 ( ) ) ;
sec_resp_handle_time . push ( sec_perf_stat . resp_handle_t . as_secs_f64 ( ) ) ;
three_req_size . push ( three_perf_stat . req_len as f64 ) ;
three_req_time . push ( three_perf_stat . req_t . as_secs_f64 ( ) ) ;
three_resp_size . push ( three_perf_stat . resp_len as f64 ) ;
three_resp_time . push ( three_perf_stat . resp_t . as_secs_f64 ( ) ) ;
three_resp_handle_time . push ( three_perf_stat . resp_handle_t . as_secs_f64 ( ) ) ;
four_req_size . push ( four_perf_stat . req_len as f64 ) ;
four_req_time . push ( four_perf_stat . req_t . as_secs_f64 ( ) ) ;
four_resp_size . push ( four_perf_stat . resp_len as f64 ) ;
four_resp_time . push ( four_perf_stat . resp_t . as_secs_f64 ( ) ) ;
four_resp_handle_time . push ( four_perf_stat . resp_handle_t . as_secs_f64 ( ) ) ;
}
2021-11-23 12:02:34 -05:00
println! ( " \n ***START: {} *3*2 BUCKETS LEVELS*** \n " , x ) ;
println! ( " \n ----OPEN-INVITATION- {} --- \n " , x ) ;
2021-11-22 22:56:48 -05:00
print_stats_test_results (
open_req_size ,
open_req_time ,
open_resp_size ,
open_resp_time ,
open_resp_handle_time ,
) ;
2021-11-23 12:02:34 -05:00
println! ( " \n ----TRUST-PROMOTION-1: 30 days- {} --- \n " , x ) ;
2021-11-22 22:56:48 -05:00
print_stats_test_results (
promo_req_size ,
promo_req_time ,
promo_resp_size ,
promo_resp_time ,
promo_resp_handle_time ,
) ;
2021-11-23 12:02:34 -05:00
println! ( " \n ----TRUST-MIGRATION-0: 30 days- {} --- \n " , x ) ;
2021-11-22 22:56:48 -05:00
print_stats_test_results (
mig_req_size ,
mig_req_time ,
mig_resp_size ,
mig_resp_time ,
mig_resp_handle_time ,
) ;
2021-11-23 12:02:34 -05:00
println! ( " \n ----LEVEL-UP-2: 44 days- {} --- \n " , x ) ;
2021-11-22 22:56:48 -05:00
print_stats_test_results (
sec_req_size ,
sec_req_time ,
sec_resp_size ,
sec_resp_time ,
sec_resp_handle_time ,
) ;
2021-11-23 12:02:34 -05:00
println! ( " \n ----LEVEL-UP-3: 72 days--- {} --- \n " , x ) ;
2021-11-22 22:56:48 -05:00
print_stats_test_results (
three_req_size ,
three_req_time ,
three_resp_size ,
three_resp_time ,
three_resp_handle_time ,
) ;
2021-11-23 12:02:34 -05:00
println! ( " \n ----LEVEL-UP-4: 128 days--- {} --- \n " , x ) ;
2021-11-22 22:56:48 -05:00
print_stats_test_results (
four_req_size ,
four_req_time ,
four_resp_size ,
four_resp_time ,
four_resp_handle_time ,
) ;
2021-11-23 12:02:34 -05:00
}
}
2022-04-03 01:54:53 -04:00
#[ test ]
2021-11-23 12:02:34 -05:00
fn stats_test_invitations ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut req_size : Vec < f64 > = Vec ::new ( ) ;
let mut resp_size : Vec < f64 > = Vec ::new ( ) ;
let mut req_time : Vec < f64 > = Vec ::new ( ) ;
let mut resp_time : Vec < f64 > = Vec ::new ( ) ;
let mut resp_handle_time : Vec < f64 > = Vec ::new ( ) ;
let mut red_req_size : Vec < f64 > = Vec ::new ( ) ;
let mut red_resp_size : Vec < f64 > = Vec ::new ( ) ;
let mut red_req_time : Vec < f64 > = Vec ::new ( ) ;
let mut red_resp_time : Vec < f64 > = Vec ::new ( ) ;
let mut red_resp_handle_time : Vec < f64 > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
th . advance_days ( 28 ) ;
let ( perf_stat , ( _ , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( bob_perf_stat , _ ) = th . redeem_invite ( & invite ) ;
req_size . push ( perf_stat . req_len as f64 ) ;
req_time . push ( perf_stat . req_t . as_secs_f64 ( ) ) ;
resp_size . push ( perf_stat . resp_len as f64 ) ;
resp_time . push ( perf_stat . resp_t . as_secs_f64 ( ) ) ;
resp_handle_time . push ( perf_stat . resp_handle_t . as_secs_f64 ( ) ) ;
red_req_size . push ( bob_perf_stat . req_len as f64 ) ;
red_req_time . push ( bob_perf_stat . req_t . as_secs_f64 ( ) ) ;
red_resp_size . push ( bob_perf_stat . resp_len as f64 ) ;
red_resp_time . push ( bob_perf_stat . resp_t . as_secs_f64 ( ) ) ;
red_resp_handle_time . push ( bob_perf_stat . resp_handle_t . as_secs_f64 ( ) ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS INVITATIONS*** \n " , x ) ;
println! ( " \n ----ISSUE-INVITATION- {} --- \n " , x ) ;
2021-11-22 22:56:48 -05:00
print_stats_test_results ( req_size , req_time , resp_size , resp_time , resp_handle_time ) ;
2021-11-23 12:02:34 -05:00
println! ( " \n ----REDEEM-INVITATION- {} --- \n " , x ) ;
2021-11-22 22:56:48 -05:00
print_stats_test_results (
2021-11-23 12:02:34 -05:00
red_req_size ,
red_req_time ,
red_resp_size ,
red_resp_time ,
red_resp_handle_time ,
) ;
}
}
2022-04-03 01:54:53 -04:00
#[ test ]
2022-04-04 13:22:51 -04:00
fn stats_test_percent_blockage_migration_05 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-22 22:56:48 -05:00
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 5*** \n " , x ) ;
block_bridges ( & mut th , 5 , credentials ) ;
}
}
2022-04-03 01:54:53 -04:00
#[ test ]
2022-04-04 13:22:51 -04:00
fn stats_test_percent_blockage_migration_010 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
2021-11-22 22:56:48 -05:00
2021-11-23 12:02:34 -05:00
println! ( " \n ***START: {} *3*2 BUCKETS 10*** \n " , x ) ;
2021-11-22 22:56:48 -05:00
block_bridges ( & mut th , 10 , credentials ) ;
}
}
2022-04-03 01:54:53 -04:00
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_15 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-22 22:56:48 -05:00
for x in buckets {
2021-11-23 12:02:34 -05:00
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
2021-11-22 22:56:48 -05:00
2021-11-23 12:02:34 -05:00
println! ( " \n ***START: {} *3*2 BUCKETS 15*** \n " , x ) ;
block_bridges ( & mut th , 15 , credentials ) ;
2021-11-22 22:56:48 -05:00
}
2021-11-23 12:02:34 -05:00
}
2021-11-22 22:56:48 -05:00
2022-04-03 01:54:53 -04:00
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_20 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-22 22:56:48 -05:00
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 20*** \n " , x ) ;
block_bridges ( & mut th , 20 , credentials ) ;
2021-11-22 22:56:48 -05:00
}
2021-11-23 12:02:34 -05:00
}
2021-11-22 22:56:48 -05:00
2022-04-03 01:54:53 -04:00
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_25 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-22 22:56:48 -05:00
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 25*** \n " , x ) ;
block_bridges ( & mut th , 25 , credentials ) ;
}
}
2022-04-03 01:54:53 -04:00
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_30 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 30*** \n " , x ) ;
block_bridges ( & mut th , 30 , credentials ) ;
}
}
2022-04-03 01:54:53 -04:00
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_35 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 35*** \n " , x ) ;
block_bridges ( & mut th , 35 , credentials ) ;
}
}
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_40 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 40*** \n " , x ) ;
block_bridges ( & mut th , 40 , credentials ) ;
}
}
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_45 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 45*** \n " , x ) ;
block_bridges ( & mut th , 45 , credentials ) ;
}
}
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_50 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 50*** \n " , x ) ;
block_bridges ( & mut th , 50 , credentials ) ;
}
}
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_55 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 55*** \n " , x ) ;
block_bridges ( & mut th , 55 , credentials ) ;
}
}
2022-04-03 01:54:53 -04:00
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_60 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 60*** \n " , x ) ;
block_bridges ( & mut th , 60 , credentials ) ;
}
}
2022-04-03 01:54:53 -04:00
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_65 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 65*** \n " , x ) ;
block_bridges ( & mut th , 65 , credentials ) ;
}
}
2022-04-03 01:54:53 -04:00
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_70 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 70*** \n " , x ) ;
block_bridges ( & mut th , 70 , credentials ) ;
}
}
2022-04-03 01:54:53 -04:00
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_75 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 75*** \n " , x ) ;
block_bridges ( & mut th , 75 , credentials ) ;
}
}
2022-04-03 01:54:53 -04:00
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_80 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 80*** \n " , x ) ;
block_bridges ( & mut th , 80 , credentials ) ;
}
}
2022-04-03 01:54:53 -04:00
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_85 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 85*** \n " , x ) ;
block_bridges ( & mut th , 85 , credentials ) ;
}
}
2022-04-03 01:54:53 -04:00
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_90 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 90*** \n " , x ) ;
block_bridges ( & mut th , 90 , credentials ) ;
}
}
2022-04-03 01:54:53 -04:00
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_95 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 95*** \n " , x ) ;
block_bridges ( & mut th , 95 , credentials ) ;
}
}
2022-04-03 01:54:53 -04:00
#[ test ]
2022-04-04 00:42:20 -04:00
fn stats_test_percent_blockage_migration_100 ( ) {
2022-04-03 01:54:53 -04:00
let buckets : Vec < u16 > = vec! [ 150 , 300 , 450 , 600 , 750 , 900 , 1050 , 1200 , 1350 , 1500 ] ;
2021-11-23 12:02:34 -05:00
for x in buckets {
let mut th = TestHarness ::new_buckets ( x , x ) ;
let mut credentials : Vec < cred ::Lox > = Vec ::new ( ) ;
2022-10-11 02:46:04 -04:00
for _ in 0 .. USERS {
2022-10-20 11:34:39 -04:00
let h : NaiveTime = DateTime ::time ( & Utc ::now ( ) ) ;
2022-04-03 01:03:35 -04:00
if h . hour ( ) = = 23 & & h . minute ( ) = = 59 {
2022-04-03 01:54:53 -04:00
println! ( " Wait for UTC 00:00 " ) ;
2022-10-20 11:34:39 -04:00
thread ::sleep ( Duration ::new ( 60 , 0 ) ) ;
2022-04-03 01:03:35 -04:00
println! ( " Ready to work again " ) ;
2022-04-04 00:42:20 -04:00
}
2021-11-23 12:02:34 -05:00
let cred = th . open_invite ( ) . 1 . 0 ;
th . advance_days ( 30 ) ;
let ( _ , migcred ) = th . trust_promotion ( & cred ) ;
let ( _ , cred1 ) = th . level0_migration ( & cred , & migcred ) ;
th . advance_days ( 14 ) ;
let ( _ , cred2 ) = th . level_up ( & cred1 ) ;
let ( _ , ( cred2a , invite ) ) = th . issue_invite ( & cred2 ) ;
let ( _ , bob_cred ) = th . redeem_invite ( & invite ) ;
th . advance_days ( 28 ) ;
let ( _ , _ ) = th . level_up ( & bob_cred ) ;
let ( _ , cred3 ) = th . level_up ( & cred2a ) ;
credentials . push ( cred3 ) ;
}
println! ( " \n ***START: {} *3*2 BUCKETS 100*** \n " , x ) ;
block_bridges ( & mut th , 100 , credentials ) ;
}
2021-11-22 22:56:48 -05:00
}
2021-07-18 18:51:49 -04:00
/// Blocks a percentage of the bridges for the passed Test Harness
/// excluding the hot spare buckets as they will not have been handed out.
/// The logic assumes hot spare buckets are appended to the end of the bridge_table
/// bucket list.
2021-07-06 18:08:52 -04:00
fn block_bridges ( th : & mut TestHarness , percentage : usize , credentials : Vec < cred ::Lox > ) {
2021-07-26 15:12:39 -04:00
let blockable_num = th . ba . bridge_table . buckets . len ( )
- th . ba . bridge_table . spares . len ( )
- th . bdb . openinv_buckets . len ( ) ;
let blockable_range = th . ba . bridge_table . buckets . len ( ) - th . ba . bridge_table . spares . len ( ) ;
2022-10-18 00:51:17 -04:00
let to_block : usize = blockable_num * percentage / 100 ;
2021-07-06 18:08:52 -04:00
let mut block_index : HashSet < usize > = HashSet ::new ( ) ;
let mut rng = rand ::thread_rng ( ) ;
2022-10-18 00:51:17 -04:00
while block_index . len ( ) < to_block {
2021-07-26 15:12:39 -04:00
let rand_num = rng . gen_range ( 0 , blockable_range ) ;
if ! th . bdb . openinv_buckets . contains ( & ( rand_num as u32 ) ) {
block_index . insert ( rand_num ) ;
}
2021-07-06 18:08:52 -04:00
}
for index in block_index {
let b0 = th . ba . bridge_table . buckets [ index ] [ 0 ] ;
let b1 = th . ba . bridge_table . buckets [ index ] [ 1 ] ;
let b2 = th . ba . bridge_table . buckets [ index ] [ 2 ] ;
th . ba . bridge_unreachable ( & b0 , & mut th . bdb ) ;
th . ba . bridge_unreachable ( & b1 , & mut th . bdb ) ;
th . ba . bridge_unreachable ( & b2 , & mut th . bdb ) ;
}
2021-06-23 01:23:19 -04:00
let mut req_size : Vec < f64 > = Vec ::new ( ) ;
let mut resp_size : Vec < f64 > = Vec ::new ( ) ;
2021-09-29 01:11:12 -04:00
let mut req_time : Vec < f64 > = Vec ::new ( ) ;
let mut resp_time : Vec < f64 > = Vec ::new ( ) ;
let mut resp_handle_time : Vec < f64 > = Vec ::new ( ) ;
2021-06-23 01:23:19 -04:00
let mut red_req_size : Vec < f64 > = Vec ::new ( ) ;
let mut red_resp_size : Vec < f64 > = Vec ::new ( ) ;
2021-09-29 01:11:12 -04:00
let mut red_req_time : Vec < f64 > = Vec ::new ( ) ;
let mut red_resp_time : Vec < f64 > = Vec ::new ( ) ;
let mut red_resp_handle_time : Vec < f64 > = Vec ::new ( ) ;
2021-07-06 18:08:52 -04:00
for cred in credentials {
let ( id , key ) = bridge_table ::from_scalar ( cred . bucket ) . unwrap ( ) ;
2021-06-25 01:49:58 -04:00
let encbuckets = th . ba . enc_bridge_table ( ) ;
let bucket =
bridge_table ::BridgeTable ::decrypt_bucket ( id , & key , & encbuckets [ id as usize ] ) . unwrap ( ) ;
2021-07-06 18:08:52 -04:00
let mut count = 0 ;
for bridge_line in & bucket . 0 {
if th . ba . bridge_table . reachable . contains_key ( bridge_line ) {
2022-10-18 00:51:17 -04:00
count + = 1 ;
2021-07-06 18:08:52 -04:00
}
}
if count < 2 {
let ( perf_stat , migration ) = th . check_blockage ( & cred ) ;
let ( block_perf_stat , _ ) = th . blockage_migration ( & cred , & migration ) ;
req_size . push ( perf_stat . req_len as f64 ) ;
2021-09-29 01:11:12 -04:00
req_time . push ( perf_stat . req_t . as_secs_f64 ( ) ) ;
2021-07-06 18:08:52 -04:00
resp_size . push ( perf_stat . resp_len as f64 ) ;
2021-09-29 01:11:12 -04:00
resp_time . push ( perf_stat . resp_t . as_secs_f64 ( ) ) ;
resp_handle_time . push ( perf_stat . resp_handle_t . as_secs_f64 ( ) ) ;
2021-07-06 18:08:52 -04:00
red_req_size . push ( block_perf_stat . req_len as f64 ) ;
2021-09-29 01:11:12 -04:00
red_req_time . push ( block_perf_stat . req_t . as_secs_f64 ( ) ) ;
2021-07-06 18:08:52 -04:00
red_resp_size . push ( block_perf_stat . resp_len as f64 ) ;
2021-09-29 01:11:12 -04:00
red_resp_time . push ( block_perf_stat . resp_t . as_secs_f64 ( ) ) ;
red_resp_handle_time . push ( block_perf_stat . resp_handle_t . as_secs_f64 ( ) ) ;
2021-07-06 18:08:52 -04:00
}
2021-06-23 01:23:19 -04:00
}
2021-11-23 12:02:34 -05:00
println! ( " \n ----CHECK-BLOCKAGE- {} ---- \n " , percentage ) ;
2021-09-29 01:11:12 -04:00
print_stats_test_results ( req_size , req_time , resp_size , resp_time , resp_handle_time ) ;
2021-06-23 01:23:19 -04:00
2021-11-23 12:02:34 -05:00
println! ( " \n ----BLOCKAGE-MIGRATION- {} ---- \n " , percentage ) ;
2021-06-23 01:23:19 -04:00
print_stats_test_results (
red_req_size ,
2021-09-29 01:11:12 -04:00
red_req_time ,
2021-06-23 01:23:19 -04:00
red_resp_size ,
2021-09-29 01:11:12 -04:00
red_resp_time ,
red_resp_handle_time ,
2021-06-23 01:23:19 -04:00
) ;
2021-06-22 14:43:15 -04:00
}
fn print_test_results ( perf_stat : PerfStat ) {
2021-07-07 11:28:17 -04:00
println! ( " Request size = {:?} bytes " , perf_stat . req_len ) ;
2021-06-22 14:43:15 -04:00
println! ( " Request time = {:?} " , perf_stat . req_t ) ;
2021-07-07 11:28:17 -04:00
println! ( " Response size = {:?} bytes " , perf_stat . resp_len ) ;
2021-06-22 14:43:15 -04:00
println! ( " Response time = {:?} " , perf_stat . resp_t ) ;
println! ( " Response handle time = {:?} " , perf_stat . resp_handle_t ) ;
}
2022-04-03 01:54:53 -04:00
//fn print_time_test_results(perf_stat: PerfStat) {
// println!("Request time = {:?}", perf_stat.req_t);
// println!("Response time = {:?}", perf_stat.resp_t);
// println!("Response handle time = {:?}", perf_stat.resp_handle_t);
//}
2021-09-29 01:11:12 -04:00
2021-06-22 14:43:15 -04:00
fn print_stats_test_results (
req_size : Vec < f64 > ,
2021-09-29 01:11:12 -04:00
req_time : Vec < f64 > ,
2021-06-22 14:43:15 -04:00
resp_size : Vec < f64 > ,
2021-09-29 01:11:12 -04:00
resp_time : Vec < f64 > ,
resp_handle_time : Vec < f64 > ,
2021-06-22 14:43:15 -04:00
) {
2022-10-20 11:34:39 -04:00
let mean_req_size = if req_size . len ( ) > 0 {
mean ( & req_size )
} else {
0.0
} ;
let req_std_dev = if req_size . len ( ) > 1 {
standard_deviation ( & req_size , Some ( mean_req_size ) )
} else {
0.0
} ;
let mean_req_time = if req_time . len ( ) > 0 {
mean ( & req_time )
} else {
0.0
} ;
let req_time_std_dev = if req_time . len ( ) > 1 {
standard_deviation ( & req_time , Some ( mean_req_time ) )
} else {
0.0
} ;
let mean_resp_size = if resp_size . len ( ) > 0 {
mean ( & resp_size )
} else {
0.0
} ;
let resp_std_dev = if resp_size . len ( ) > 1 {
standard_deviation ( & resp_size , Some ( mean_resp_size ) )
} else {
0.0
} ;
let mean_resp_time = if resp_time . len ( ) > 0 {
mean ( & resp_time )
} else {
0.0
} ;
let resp_time_std_dev = if resp_time . len ( ) > 1 {
standard_deviation ( & resp_time , Some ( mean_resp_time ) )
} else {
0.0
} ;
let mean_resp_handle_time = if resp_handle_time . len ( ) > 0 {
mean ( & resp_handle_time )
} else {
0.0
} ;
let resp_handle_time_std_dev = if resp_handle_time . len ( ) > 1 {
standard_deviation ( & resp_handle_time , Some ( mean_resp_handle_time ) )
} else {
0.0
} ;
2021-06-22 14:43:15 -04:00
2021-07-07 11:28:17 -04:00
println! ( " Average request size = {} bytes " , mean_req_size ) ;
println! ( " Request size standard deviation = {} bytes " , req_std_dev ) ;
2021-06-15 02:01:24 -04:00
println! (
2021-07-07 11:28:17 -04:00
" Average request time = {:?} " ,
2021-09-29 01:11:12 -04:00
Duration ::from_secs_f64 ( mean_req_time )
2021-06-15 02:01:24 -04:00
) ;
println! (
2021-07-07 11:28:17 -04:00
" Request time standard deviation = {:?} " ,
2021-09-29 01:11:12 -04:00
Duration ::from_secs_f64 ( req_time_std_dev )
2021-06-15 02:01:24 -04:00
) ;
2021-07-07 11:28:17 -04:00
println! ( " Average response size = {} bytes " , mean_resp_size ) ;
println! ( " Response standard deviation = {} bytes " , resp_std_dev ) ;
2021-06-15 02:01:24 -04:00
println! (
2021-07-07 11:28:17 -04:00
" Average response time = {:?} " ,
2021-09-29 01:11:12 -04:00
Duration ::from_secs_f64 ( mean_resp_time )
2021-06-15 02:01:24 -04:00
) ;
println! (
2021-07-07 11:28:17 -04:00
" Response time standard deviation = {:?} " ,
2021-09-29 01:11:12 -04:00
Duration ::from_secs_f64 ( resp_time_std_dev )
2021-06-15 02:01:24 -04:00
) ;
println! (
2021-07-07 11:28:17 -04:00
" Average response handling time = {:?} " ,
2021-09-29 01:11:12 -04:00
Duration ::from_secs_f64 ( mean_resp_handle_time )
2021-06-15 02:01:24 -04:00
) ;
println! (
2021-07-07 11:28:17 -04:00
" Response handling time standard deviation = {:?} " ,
2021-09-29 01:11:12 -04:00
Duration ::from_secs_f64 ( resp_handle_time_std_dev )
2021-06-15 02:01:24 -04:00
) ;
}