Browse Source

Added timing

onyinyang 2 years ago
parent
commit
634f8c9b35
2 changed files with 186 additions and 50 deletions
  1. 1 0
      Cargo.toml
  2. 185 50
      src/tests.rs

+ 1 - 0
Cargo.toml

@@ -10,6 +10,7 @@ ed25519-dalek = "1"
 # zkp = { version = "0.8", features = ["debug-transcript"] }
 zkp = "0.8"
 bincode = "1"
+chrono = "0.4"
 rand = "0.7"
 serde = "1"
 serde_with = "1.9.1"

+ 185 - 50
src/tests.rs

@@ -4,9 +4,11 @@ BridgeLine::random() or private fields */
 use super::bridge_table::BridgeLine;
 use super::proto::*;
 use super::*;
+use chrono::{Utc, DateTime, NaiveTime, Timelike};
 use rand::Rng;
 use statistical::{mean, standard_deviation};
 use std::collections::HashSet;
+use std::thread;
 use std::time::{Duration, Instant};
 
 struct PerfStat {
@@ -370,7 +372,7 @@ impl TestHarness {
     }
 }
 
-#[test]
+//#[test]
 fn test_open_invite() {
     let mut th = TestHarness::new();
 
@@ -391,7 +393,7 @@ fn test_open_invite() {
     assert!(bridgeline == bucket.0[0]);
 }
 
-#[test]
+//#[test]
 fn test_trust_promotion() {
     let mut th = TestHarness::new();
 
@@ -415,7 +417,7 @@ fn test_trust_promotion() {
     assert!(th.ba.verify_reachability(&bucket.1.unwrap()));
 }
 
-#[test]
+//#[test]
 fn test_level0_migration() {
     let mut th = TestHarness::new();
 
@@ -446,7 +448,7 @@ fn test_level0_migration() {
     assert!(th.ba.verify_reachability(&bucket.1.unwrap()));
 }
 
-#[test]
+//#[test]
 fn test_level_up() {
     let mut th = TestHarness::new();
 
@@ -501,7 +503,7 @@ fn test_level_up() {
     assert!(th.ba.verify_lox(&cred4));
 }
 
-#[test]
+//#[test]
 fn test_issue_invite() {
     let mut th = TestHarness::new();
 
@@ -541,7 +543,7 @@ fn test_issue_invite() {
     println!("invite = {:?}", invite);
 }
 
-#[test]
+//#[test]
 fn test_redeem_invite() {
     let mut th = TestHarness::new();
 
@@ -591,7 +593,7 @@ fn test_redeem_invite() {
     println!("bob_cred = {:?}", bob_cred);
 }
 
-#[test]
+//#[test]
 fn test_mark_unreachable() {
     let mut th = TestHarness::new();
 
@@ -641,7 +643,7 @@ fn test_mark_unreachable() {
     println!("openinv = {:?}\n", th.bdb.openinv_buckets);
 }
 
-#[test]
+//#[test]
 fn test_blockage_migration() {
     let mut th = TestHarness::new();
 
@@ -712,9 +714,9 @@ fn test_blockage_migration() {
     assert!(th.ba.verify_lox(&cred4));
 }
 
-#[test]
+//#[test]
 fn stats_test_trust_levels() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![900, 1050, 1200, 1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
@@ -750,6 +752,12 @@ fn stats_test_trust_levels() {
         let mut open_resp_time: Vec<f64> = Vec::new();
         let mut open_resp_handle_time: Vec<f64> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let (open_perf_stat, cred) = th.open_invite();
             th.advance_days(30);
             let (tp_perf_stat, migcred) = th.trust_promotion(&cred.0);
@@ -849,9 +857,9 @@ fn stats_test_trust_levels() {
     }
 }
 
-#[test]
+//#[test]
 fn stats_test_invitations() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![1050, 1200, 1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
@@ -867,6 +875,13 @@ fn stats_test_invitations() {
         let mut red_resp_time: Vec<f64> = Vec::new();
         let mut red_resp_handle_time: Vec<f64> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -903,14 +918,20 @@ fn stats_test_invitations() {
     }
 }
 
-#[test]
+//#[test]
 fn stats_test_blockage_migration_5() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
-        for _ in 0..1000 {
+        for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -930,14 +951,20 @@ fn stats_test_blockage_migration_5() {
     }
 }
 
-#[test]
+//#[test]
 fn stats_test_blockage_migration_10() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![1050, 1200, 1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
-        for _ in 0..1000 {
+        for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -957,14 +984,20 @@ fn stats_test_blockage_migration_10() {
     }
 }
 
-#[test]
+//#[test]
 fn stats_test_blockage_migration_15() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![1050, 1200, 1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -984,14 +1017,20 @@ fn stats_test_blockage_migration_15() {
     }
 }
 
-#[test]
+//#[test]
 fn stats_test_blockage_migration_20() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -1011,14 +1050,20 @@ fn stats_test_blockage_migration_20() {
     }
 }
 
-#[test]
+//#[test]
 fn stats_test_blockage_migration_25() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -1038,14 +1083,20 @@ fn stats_test_blockage_migration_25() {
     }
 }
 
-#[test]
+//#[test]
 fn stats_test_blockage_migration_30() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![1050, 1200, 1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -1065,14 +1116,20 @@ fn stats_test_blockage_migration_30() {
     }
 }
 
-#[test]
+//#[test]
 fn stats_test_blockage_migration_35() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![1200, 1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -1094,12 +1151,18 @@ fn stats_test_blockage_migration_35() {
 
 #[test]
 fn stats_test_blockage_migration_40() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![900];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -1121,12 +1184,18 @@ fn stats_test_blockage_migration_40() {
 
 #[test]
 fn stats_test_blockage_migration_45() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![900];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -1148,12 +1217,18 @@ fn stats_test_blockage_migration_45() {
 
 #[test]
 fn stats_test_blockage_migration_50() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -1175,12 +1250,18 @@ fn stats_test_blockage_migration_50() {
 
 #[test]
 fn stats_test_blockage_migration_55() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![900];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -1200,14 +1281,20 @@ fn stats_test_blockage_migration_55() {
     }
 }
 
-#[test]
+////#[test]
 fn stats_test_blockage_migration_60() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![1200, 1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -1227,14 +1314,20 @@ fn stats_test_blockage_migration_60() {
     }
 }
 
-#[test]
+//#[test]
 fn stats_test_blockage_migration_65() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![1200, 1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -1254,14 +1347,20 @@ fn stats_test_blockage_migration_65() {
     }
 }
 
-#[test]
+//#[test]
 fn stats_test_blockage_migration_70() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![1200, 1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -1281,14 +1380,20 @@ fn stats_test_blockage_migration_70() {
     }
 }
 
-#[test]
+//#[test]
 fn stats_test_blockage_migration_75() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![1200, 1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -1308,14 +1413,20 @@ fn stats_test_blockage_migration_75() {
     }
 }
 
-#[test]
+//#[test]
 fn stats_test_blockage_migration_80() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![900, 1050, 1200, 1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -1335,14 +1446,20 @@ fn stats_test_blockage_migration_80() {
     }
 }
 
-#[test]
+//#[test]
 fn stats_test_blockage_migration_85() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![1050, 1200, 1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -1362,14 +1479,20 @@ fn stats_test_blockage_migration_85() {
     }
 }
 
-#[test]
+//#[test]
 fn stats_test_blockage_migration_90() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -1389,14 +1512,20 @@ fn stats_test_blockage_migration_90() {
     }
 }
 
-#[test]
+//#[test]
 fn stats_test_blockage_migration_95() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![1050, 1200, 1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);
@@ -1416,14 +1545,20 @@ fn stats_test_blockage_migration_95() {
     }
 }
 
-#[test]
+//#[test]
 fn stats_test_blockage_migration_100() {
-    let buckets: Vec<u16> = vec![150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500];
+    let buckets: Vec<u16> = vec![750, 900, 1050, 1200, 1350, 1500];
 
     for x in buckets {
         let mut th = TestHarness::new_buckets(x, x);
         let mut credentials: Vec<cred::Lox> = Vec::new();
         for _ in 0..10000 {
+	    let h: NaiveTime = DateTime::time(&Utc::now());
+            if h.hour() == 23 && h.minute() == 59 {
+                println!("Biding my time for a minute");
+		thread::sleep(Duration::new(60,0));
+                println!("Ready to work again");
+            } 
             let cred = th.open_invite().1 .0;
             th.advance_days(30);
             let (_, migcred) = th.trust_promotion(&cred);