@mark1russell7/harness 0.16.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js CHANGED
@@ -2111,6 +2111,15 @@ const measurePorts = (run, expected) => {
2111
2111
  };
2112
2112
  // src/recovery.ts
2113
2113
  /**
2114
+ * This function gives the state of a set that did not elect a primary after a restore. The text has
2115
+ * the view of the old primary (the output of `STATUS_SCRIPT`). It also has the last `ELECTION_LINES`
2116
+ * lines of the components ELECTION and REPL, from index `from` of the log.
2117
+ */
2118
+ const electionStateText = (primary, status, log, from) => {
2119
+ const lines = log.slice(from).filter((line) => line.c === "ELECTION" || line.c === "REPL").slice(-8).map((line) => `${line.member} ${line.c} ${line.msg}`);
2120
+ return `The view of ${primary}: ${status.trim()}. Its last lines of the election: ${lines.length === 0 ? "none" : lines.join(" | ")}`;
2121
+ };
2122
+ /**
2114
2123
  * This module holds the pure parts of a recovery drill. These are the scripts of the shell, the reader
2115
2124
  * of the output of `bsondump`, and the set check of a recovery. It has no container, thus unit tests
2116
2125
  * run it. `drill.ts` does the drill on a lab.
@@ -6704,14 +6713,25 @@ const replicaSetOnce = async (lab, cell, environment, index) => {
6704
6713
  const VAULT = "/backup";
6705
6714
  /** This time is the longest wait for a server to answer, in ms. */
6706
6715
  const STARTS_WITHIN = 6e4;
6707
- /** This function waits until a check holds, or it stops the run after `within` ms. */
6708
- const until = async (what, check, within) => {
6716
+ /**
6717
+ * This function waits until a check holds, or it stops the run after `within` ms. At the stop, the
6718
+ * error also gives the text of `explain`: the state that tells why the check did not hold.
6719
+ */
6720
+ const until = async (what, check, within, explain) => {
6709
6721
  const started = Date.now();
6710
6722
  while (!await check().catch(() => false)) {
6711
- if (Date.now() - started > within) throw new Error(`${what} did not come in ${within} ms`);
6723
+ if (Date.now() - started > within) {
6724
+ const state = explain === void 0 ? "" : `. ${await explain().catch((error) => `No state: ${error instanceof Error ? error.message : String(error)}`)}`;
6725
+ throw new Error(`${what} did not come in ${within} ms${state}`);
6726
+ }
6712
6727
  await setTimeout$1(500);
6713
6728
  }
6714
6729
  };
6730
+ /** This function reads the state of a set that did not elect a primary after a restore (`electionStateText`). */
6731
+ const electionStateOf = async (lab, primary, logFrom) => {
6732
+ const status = await lab.script(primary, STATUS_SCRIPT).catch((error) => `no status (${error instanceof Error ? error.message : String(error)})`);
6733
+ return electionStateText(primary, status, lab.log, logFrom);
6734
+ };
6715
6735
  /** This function gives the time that the client sent a write. Zero is no write. */
6716
6736
  const writeOf = (events, n) => {
6717
6737
  const sent = n === 0 ? void 0 : events.find((event) => event.ev === "sent" && Number(event["n"]) === n);
@@ -6868,6 +6888,7 @@ const lose = async (lab, drill, primary, last) => {
6868
6888
  const restore = async (lab, drill, primary) => {
6869
6889
  const { set } = lab;
6870
6890
  const started = Date.now();
6891
+ const logFrom = lab.log.length;
6871
6892
  const port = set.port + 1;
6872
6893
  const slices = Array.from({ length: drill.slices }, (_, at) => `${VAULT}/slice-${at + 1}/local/oplog.rs.bson`);
6873
6894
  if (slices.length > 0) await lab.vault([
@@ -6898,7 +6919,7 @@ const restore = async (lab, drill, primary) => {
6898
6919
  const ips = Object.fromEntries(Object.entries(lab.members).map(([name, at]) => [name, at.ip]));
6899
6920
  const initiated = await lab.script(primary, initiateScript(set, ips));
6900
6921
  if (!initiated.includes("\"ok\":1")) throw new Error(`rs.initiate failed after the restore: ${initiated}`);
6901
- await until("the primary after the restore", async () => (await lab.script(primary, "print(db.hello().isWritablePrimary)")).includes("true"), STARTS_WITHIN);
6922
+ await until("the primary after the restore", async () => (await lab.script(primary, "print(db.hello().isWritablePrimary)")).includes("true"), STARTS_WITHIN, () => electionStateOf(lab, primary, logFrom));
6902
6923
  return {
6903
6924
  started,
6904
6925
  ended: Date.now()