[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [tor/master 12/28] Fix CBT unit tests.
Author: Mike Perry <mikeperry-git@xxxxxxxxxx>
Date: Wed, 12 May 2010 15:31:22 -0700
Subject: Fix CBT unit tests.
Commit: d9be6f38450fd4c20f5c3711e68676547997b23c
---
src/or/circuitbuild.c | 40 +++++++++++++++++++++++++---------------
src/test/test.c | 4 ++--
2 files changed, 27 insertions(+), 17 deletions(-)
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 1d4d267..97e7c1c 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -84,22 +84,26 @@ static void entry_guards_changed(void);
static int
circuit_build_times_disabled(void)
{
- int consensus_disabled = networkstatus_get_param(NULL, "cbtdisabled",
- 0);
- int config_disabled = !get_options()->LearnCircuitBuildTimeout;
- int dirauth_disabled = get_options()->AuthoritativeDir;
- int state_disabled = (get_or_state()->LastWritten == -1);
-
- if (consensus_disabled || config_disabled || dirauth_disabled ||
- state_disabled) {
- log_info(LD_CIRC,
- "CircuitBuildTime learning is disabled. "
- "Consensus=%d, Config=%d, AuthDir=%d, StateFile=%d",
- consensus_disabled, config_disabled, dirauth_disabled,
- state_disabled);
- return 1;
- } else {
+ if (unit_tests) {
return 0;
+ } else {
+ int consensus_disabled = networkstatus_get_param(NULL, "cbtdisabled",
+ 0);
+ int config_disabled = !get_options()->LearnCircuitBuildTimeout;
+ int dirauth_disabled = get_options()->AuthoritativeDir;
+ int state_disabled = (get_or_state()->LastWritten == -1);
+
+ if (consensus_disabled || config_disabled || dirauth_disabled ||
+ state_disabled) {
+ log_info(LD_CIRC,
+ "CircuitBuildTime learning is disabled. "
+ "Consensus=%d, Config=%d, AuthDir=%d, StateFile=%d",
+ consensus_disabled, config_disabled, dirauth_disabled,
+ state_disabled);
+ return 1;
+ } else {
+ return 0;
+ }
}
}
@@ -1104,6 +1108,12 @@ circuit_build_times_filter_timeouts(circuit_build_times_t *cbt)
return 0;
}
+ /* Do not filter for unit tests. They expect the distribution to be
+ * unchanged from run to run. */
+ if (unit_tests) {
+ return 0;
+ }
+
timeout_rate = circuit_build_times_timeout_rate(cbt);
max_timeout = (build_time_t)tor_lround(circuit_build_times_calculate_timeout(cbt,
circuit_build_times_max_synthetic_quantile()));
diff --git a/src/test/test.c b/src/test/test.c
index 8d59698..eb06c76 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -494,7 +494,7 @@ test_circuit_timeout(void)
timeout1 = circuit_build_times_calculate_timeout(&estimate,
CBT_DEFAULT_QUANTILE_CUTOFF/100.0);
circuit_build_times_set_timeout(&estimate);
- log_warn(LD_CIRC, "Timeout is %lf, Xm is %d", timeout1, estimate.Xm);
+ log_warn(LD_CIRC, "Timeout1 is %lf, Xm is %d", timeout1, estimate.Xm);
/* XXX: 5% distribution error may not be the right metric */
} while (fabs(circuit_build_times_cdf(&initial, timeout0) -
circuit_build_times_cdf(&initial, timeout1)) > 0.05
@@ -511,7 +511,7 @@ test_circuit_timeout(void)
CBT_DEFAULT_QUANTILE_CUTOFF/100.0);
circuit_build_times_set_timeout(&final);
- log_warn(LD_CIRC, "Timeout is %lf, Xm is %d", timeout2, final.Xm);
+ log_warn(LD_CIRC, "Timeout2 is %lf, Xm is %d", timeout2, final.Xm);
test_assert(fabs(circuit_build_times_cdf(&initial, timeout0) -
circuit_build_times_cdf(&initial, timeout2)) < 0.05);
--
1.7.1