message: Ping only once per max-length round; fix tests.
diff: @@ -211,8 +211,10 @@ impl<C: Context> ActiveValidator<C> {
  }
  }
  }
  - // We are not creating a new unit. Send a ping if necessary, to show that we're online.
  - if !state.has_ping(self.vidx, timestamp) {
  + // We are not creating a new unit. Send a ping once per maximum-length round, to show that
  + // we're online.
  + let one_max_round_ago = timestamp.saturating_sub(state.params().max_round_length());
  + if !state.has_ping(self.vidx, one_max_round_ago + 1.into()) {
  warn!(%timestamp, "too many validators offline, sending ping");
  effects.push(self.send_ping(timestamp, instance_id));
  }
  @@ -692,7 +694,7 @@ mod tests {
  impl TestState {
  fn new(
  - state: State<TestContext>,
  + mut state: State<TestContext>,
  start_time: Timestamp,
  instance_id: u64,
  fd: FinalityDetector<TestContext>,
  @@ -706,9 +708,8 @@ mod tests {
  current_round_id + state::round_len(state.params().init_round_exp())
  };
  let target_ftt = state.total_weight() / 3;
  - let active_validators = validators
  - .into_iter()
  - .map(|vidx| {
  + let mut active_validators = Vec::with_capacity(validators.len());
  + for vidx in validators {
  let secret = TestSecret(vidx.0);
  let (av, effects) = ActiveValidator::new(
  vidx,
  @@ -721,14 +722,15 @@ mod tests {
  TEST_INSTANCE_ID,
  );
  - let timestamp = match &*effects {
  - [
  - Effect::ScheduleTimer(timer),
  - Effect::NewVertex(ValidVertex(Vertex::Ping(_)))
  - ] => { *timer }
  + let (timestamp, ping) = match &*effects {
  + [Effect::ScheduleTimer(timestamp), Effect::NewVertex(ValidVertex(Vertex::Ping(ping)))] => {
  + (*timestamp, ping)
  + }
  other => panic!("expected timer and ping effects, got={:?}", other),
  };
  + state.add_ping(ping.creator(), ping.timestamp());
  +
  if state.leader(earliest_round_start) == vidx {
  assert_eq!(
  timestamp, earliest_round_start,
  @@ -746,15 +748,14 @@ mod tests {
  )
  }
  timers.insert((timestamp, vidx));
  - av
  - })
  - .collect();
  + active_validators.push(av);
  + }
  TestState {
  state,
  instance_id,
  fd,
  - active_validators,
  + active_validators: active_validators.into_iter().collect(),
  timers,
  }
  }
  