Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/services/sync/tests/unit/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 1 kB image not shown  

Quelle  test_utils_lock.js

  Sprache: JAVA
 

_("Make sure lock prevents calling with a shared lock");

// Utility that we only use here.

function do_check_begins(thing, startsWith) {
  if (!(thing && thing.indexOf && thing.indexOf(startsWith) == 0)) {
    do_throw(thing + " doesn't begin with " + startsWith);
  }
}

add_task(async function run_test() {
  let ret, rightThis, didCall;
  let state, lockState, lockedState, unlockState;
  let obj = {
    _lock: Utils.lock,
    lock() {
      lockState = ++state;
      if (this._locked) {
        lockedState = ++state;
        return false;
      }
      this._locked = true;
      return true;
    },
    unlock() {
      unlockState = ++state;
      this._locked = false;
    },

    func() {
      return this._lock("Test utils lock", async function () {
        rightThis = this == obj;
        didCall = true;
        return 5;
      })();
    },

    throwy() {
      return this._lock("Test utils lock throwy", async function () {
        rightThis = this == obj;
        didCall = true;
        return this.throwy();
      })();
    },
  };

  _("Make sure a normal call will call and return");
  rightThis = didCall = false;
  state = 0;
  ret = await obj.func();
  Assert.equal(ret, 5);
  Assert.ok(rightThis);
  Assert.ok(didCall);
  Assert.equal(lockState, 1);
  Assert.equal(unlockState, 2);
  Assert.equal(state, 2);

  _("Make sure code that calls locked code throws");
  ret = null;
  rightThis = didCall = false;
  try {
    ret = await obj.throwy();
    do_throw("throwy internal call should have thrown!");
  } catch (ex) {
    // Should throw an Error, not a string.
    do_check_begins(ex.message, "Could not acquire lock");
  }
  Assert.equal(ret, null);
  Assert.ok(rightThis);
  Assert.ok(didCall);
  _("Lock should be called twice so state 3 is skipped");
  Assert.equal(lockState, 4);
  Assert.equal(lockedState, 5);
  Assert.equal(unlockState, 6);
  Assert.equal(state, 6);
});

Messung V0.5 in Prozent
C=92 H=95 G=93

¤ Dauer der Verarbeitung: 0.24 Sekunden  (vorverarbeitet am  2026-08-25) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.