Skip to content

Latest commit

 

History

History
49 lines (46 loc) · 2.06 KB

README.md

File metadata and controls

49 lines (46 loc) · 2.06 KB

zookeeper-mock

CircleCI

This module can be used as a Zookeeper mock to simulate race conditions in programs.

Examples of use:

        const zkc = new ZookeeperMock();
        const subPath = '/workflow-engine';
        const path1 = `${subPath}/xxx`;
        const path2 = `${subPath}/xxx`;
        const path3 = `${subPath}/xxx`;
        const data1 = 42;
        const data2 = 43;
        const data3 = 44;
        zkc.mkdirp(path1, data1, {},
                   zookeeper.CreateMode.PERSISTENT_SEQUENTIAL,
                   err => {
                       assert.ifError(err);
                       // simulate a race
                       process.nextTick(() => {
                           zkc.mkdirp(path2, data2, {},
                          zookeeper.CreateMode.PERSISTENT_SEQUENTIAL,
                                      (err, path) => {
                                          assert.ifError(err);
                                          if (path === `${path1}0000000002`) {
                                              // th1 firing
                                              return done();
                                          }
                                          return undefined;
                                      });
                       });
                       process.nextTick(() => {
                           zkc.mkdirp(path3, data3, {},
                          zookeeper.CreateMode.PERSISTENT_SEQUENTIAL,
                                      (err, path) => {
                                          assert.ifError(err);
                                          if (path === `${path1}0000000002`) {
                                              // th2 firing
                                              return done();
                                          }
                                          return undefined;
                                      });
                       });
                   });
    });