Fix unit tests that depended on monotonic msec.

This commit is contained in:
Nick Mathewson 2017-11-22 14:38:10 -05:00
parent c3c0a05f51
commit 9c37e8c8d1

View File

@ -222,7 +222,6 @@ test_oom_streambuf(void *arg)
tt_int_op(buf_get_total_allocation(), OP_EQ, 0);
monotime_coarse_set_mock_time_nsec(start_ns);
const uint32_t ts_start = monotime_coarse_get_stamp();
/* Start all circuits with a bit of data queued in cells */
@ -272,23 +271,27 @@ test_oom_streambuf(void *arg)
now_ns += 1000000000;
monotime_coarse_set_mock_time_nsec(now_ns);
tvts = monotime_coarse_get_stamp();
const uint32_t diff = tvts - ts_start;
printf("\n!!!! %u\n", (unsigned) diff);
tt_int_op(circuit_max_queued_cell_age(c1, tvts), OP_EQ, 500);
tt_int_op(circuit_max_queued_cell_age(c2, tvts), OP_EQ, 490);
tt_int_op(circuit_max_queued_cell_age(c3, tvts), OP_EQ, 480);
tt_int_op(circuit_max_queued_cell_age(c4, tvts), OP_EQ, 0);
#define ts_is_approx(ts, val) do { \
uint32_t x_ = (uint32_t) monotime_coarse_stamp_units_to_approx_msec(ts); \
tt_int_op(x_, OP_GE, val - 5); \
tt_int_op(x_, OP_LE, val + 5); \
} while (0)
tt_int_op(circuit_max_queued_data_age(c1, tvts), OP_EQ, 390);
tt_int_op(circuit_max_queued_data_age(c2, tvts), OP_EQ, 380);
tt_int_op(circuit_max_queued_data_age(c3, tvts), OP_EQ, 0);
tt_int_op(circuit_max_queued_data_age(c4, tvts), OP_EQ, 370);
ts_is_approx(circuit_max_queued_cell_age(c1, tvts), 500);
ts_is_approx(circuit_max_queued_cell_age(c2, tvts), 490);
ts_is_approx(circuit_max_queued_cell_age(c3, tvts), 480);
ts_is_approx(circuit_max_queued_cell_age(c4, tvts), 0);
tt_int_op(circuit_max_queued_item_age(c1, tvts), OP_EQ, 500);
tt_int_op(circuit_max_queued_item_age(c2, tvts), OP_EQ, 490);
tt_int_op(circuit_max_queued_item_age(c3, tvts), OP_EQ, 480);
tt_int_op(circuit_max_queued_item_age(c4, tvts), OP_EQ, 370);
ts_is_approx(circuit_max_queued_data_age(c1, tvts), 390);
ts_is_approx(circuit_max_queued_data_age(c2, tvts), 380);
ts_is_approx(circuit_max_queued_data_age(c3, tvts), 0);
ts_is_approx(circuit_max_queued_data_age(c4, tvts), 370);
ts_is_approx(circuit_max_queued_item_age(c1, tvts), 500);
ts_is_approx(circuit_max_queued_item_age(c2, tvts), 490);
ts_is_approx(circuit_max_queued_item_age(c3, tvts), 480);
ts_is_approx(circuit_max_queued_item_age(c4, tvts), 370);
tt_int_op(cell_queues_get_total_allocation(), OP_EQ,
packed_cell_mem_cost() * 80);
@ -304,7 +307,7 @@ test_oom_streambuf(void *arg)
smartlist_add(edgeconns, ec);
}
tt_int_op(buf_get_total_allocation(), OP_EQ, 4096*17*2);
tt_int_op(circuit_max_queued_item_age(c4, tvts), OP_EQ, 1000);
ts_is_approx(circuit_max_queued_item_age(c4, tvts), 1000);
tt_int_op(cell_queues_check_size(), OP_EQ, 0);