@mark1russell7/harness 0.16.6 → 0.16.7

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
@@ -7174,6 +7174,15 @@ const electionStateOf = async (lab, primary, logFrom) => {
7174
7174
  const status = await lab.script(primary, STATUS_SCRIPT).catch((error) => `no status (${error instanceof Error ? error.message : String(error)})`);
7175
7175
  return electionStateText(primary, status, lab.log, logFrom);
7176
7176
  };
7177
+ /**
7178
+ * This function tells if a member of the set accepts writes. After a restore, the old primary can
7179
+ * lose the first election to a member that made its first sync from it. The client after the restore
7180
+ * and `converge` find the primary by themselves, thus each member can be the primary.
7181
+ */
7182
+ const writableIn = async (lab) => {
7183
+ for (const name of lab.set.members) if ((await lab.script(name, "print(db.hello().isWritablePrimary)").catch(() => "")).includes("true")) return true;
7184
+ return false;
7185
+ };
7177
7186
  /** This function gives the time that the client sent a write. Zero is no write. */
7178
7187
  const writeOf = (events, n) => {
7179
7188
  const sent = n === 0 ? void 0 : events.find((event) => event.ev === "sent" && Number(event["n"]) === n);
@@ -7361,7 +7370,7 @@ const restore = async (lab, drill, primary) => {
7361
7370
  const ips = Object.fromEntries(Object.entries(lab.members).map(([name, at]) => [name, at.ip]));
7362
7371
  const initiated = await lab.script(primary, initiateScript(set, ips));
7363
7372
  if (!initiated.includes("\"ok\":1")) throw new Error(`rs.initiate failed after the restore: ${initiated}`);
7364
- await until("the primary after the restore", async () => (await lab.script(primary, "print(db.hello().isWritablePrimary)")).includes("true"), STARTS_WITHIN, () => electionStateOf(lab, primary, logFrom));
7373
+ await until("the primary after the restore", () => writableIn(lab), STARTS_WITHIN, () => electionStateOf(lab, primary, logFrom));
7365
7374
  return {
7366
7375
  started,
7367
7376
  ended: Date.now()