npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

moray-sandbox

v0.2.2

Published

Library for managing temporary, sandboxed Moray instances

Downloads

2

Readme

node-moray-sandbox

This repository is part of the Joyent Manta and Triton projects. For contribution guidelines, issues, and general documentation, visit the main Triton and Manta project pages.

Overview

This is a node library for spinning up a temporary Moray server that can be used for unit testing programs that depend on Moray. Before running, make sure that you have at least Postgres 9.2 installed. On both Mac OS X and SmartOS:

$ pkgin in postgresql92-client postgresql92-server

Each additional Moray connected to a Postgres instance maintains an additional set of connections to the database. With enough Moray instances running, you can hit Postgres' maximum connection limit, which will prevent spawning new instances. This is normally not an issue, but can be easy to hit with Postgres 9.2 on Mac OS X, where the max is 20. If that happens to you, newer versions of Postgres can help alleviate the issue.

There is also a simple tool for starting up a temporary Moray instance, if you just want something to point at while working on the Moray CLI tools, or running the moray-test-suite:

$ ./bin/run-sandbox -p 2020

If you pass --cover, then it will also produce a coverage report for the Moray server when it exits.

Examples

You can spawn a new temporary Moray instance by running:

var mod_moray_sandbox = require('moray-sandbox');

mod_moray_sandbox.create(log, function (err, moray) {
    // Do what you need with the client, and then shutdown Moray:
    moray.stop();
});

If you need multiple Moray clients that point to the same server, you can use the client's .clone() method to create a new one with the same configuration:

var clone1 = moray.clone();
var clone2 = moray.clone();

If you need to create multiple Moray instances, you can avoid the overhead of initializing multiple Postgres instances by doing:

var mod_moray_sandbox = require('moray-sandbox');

mod_moray_sandbox.createPG(log, function (err, pg) {
    pg.spawnMoray(function (err, moray1) {
        // Do what you need with the client of Moray instance #1
    });
    pg.spawnMoray(function (err, moray2) {
        // Do what you need with the client of Moray instance #2
    });
    // Once finished, call moray1.close(), moray2.close(), and pg.stop()
});

Note that the library consumer is responsible for calling .close() on every client it creates via .create(), .spawnMoray(), and .clone() before stopping Postgres. If there is only a single client, for convenience, you can call .stop() on a client and it will handle closing the client for you before stopping Postgres.

If you want to test your application's ability to handle errors, you can inject a series of errors to be returned by future Moray client calls. For example, to make the first call to .batch() actually call out to Moray, and the second one return a fake error, you can do:

moray.setMockErrors({ batch: [ null, fakeErr, fakeErr, null ] });

Passing in null in the array allows you to interleave successes and failures. If you want to check that your errors have been dequeued, you can get the remaining mock errors. For example, if .batch() should have only been called three times after setting the mock errors earlier:

var assert = require('assert-plus');

var remaining = moray.getMockErrors();
assert.deepEqual({ batch: [ null ] }, remaining, 'batch() called thrice');

You can clear out any remaining errors by calling the method with an empty object:

moray.setMockErrors({ });

Clients created using .clone() share mock errors with the original client.