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

@holochain/tryorama-stress-utils

v0.0.11

Published

Tools to help with @holochain/tryorama stress testing

Downloads

20

Readme

tryorama-stress-utils

A small API to help with writing tryorama tests involving many conductors and instances.

Includes a Batch class to wrap a collection of Conductors, which exposes helpful map functions for iterating over instances and performing operations in series or in parallel

behavior

This package also provides some helpers for running a test over and over, changing the conditions each time, until a stopping condition is met or the test breaks. Useful for running some canonical behavior over and over and ramping up the intensity until something breaks, thus finding the performance threshold.

periodically({duration, period})

Runs the specified closure once every period ms for duration ms total

stochasticPiecewise([[fn, weight]])

Returns a function. Associates a weight with each input function, so that each time the output function is called, one of the input functions will be called randomly with the specified weight. The weights are automatically normalized and need not add up to 1.

In the following example, calling fn will result in a 50% chance of calling fn1, 30% for fn2, and 20% for fn3

const fn = stochasticPiecewise([
  [fn1, 5],
  [fn2, 3],
  [fn3, 2],
])

fn()

parameterizedStages({init, stage, stageLimit, parameters, [fail], [failHandler]})

A bit like a fold/reduce function, with parameters that change during each iteration.

stage(data, params, [fail]) is the function which will be run at each iteration. It takes data, which is the value returned by the previous iteration (or init if this is the first stage); and params, which are the changing parameters. If the fail arg is passed to parameterizedStages, that function will also be injected here to cause failures.

stageLimit: number stops execution after this many iterations

parameters is an object that defines the parameters to be passed into stage, each associated with a function that will describe what the parameter will be at a given stage.

fail (optional) is a function that is injected into the stage, which is useful for integrating with other testing harnesses, for instance when using Tape, setting fail = t.fail leads to a better experience

failHandler is a closure that will get called at test instantiation, and allows one-time access to the fail function outside of this class. This allows external code to cause the test to fail, useful for e.g. implementing a global timeout for tests in your test suite, where any test will be ended after that timeout.

Full example with tryorama:


import * as R from 'ramda'

import { Config } from '@holochain/tryorama'
import { Orchestrator, tapeExecutor, singleConductor, compose, localOnly, groupPlayersByMachine } from '@holochain/tryorama'
import { parameterizedStages, periodically } from '@holochain/tryorama-stress-utils'

process.on('unhandledRejection', error => {
  console.error('got unhandledRejection:', error);
});

const network = {
  type: 'sim2h',
  sim2h_url: "ws://localhost:9002",
}

const dna = Config.dna('../dist/passthrough-dna.dna.json', 'passthrough')

console.log("using dna: "+ JSON.stringify(dna))
console.log("using network: "+ JSON.stringify(network))
const orchestrator = new Orchestrator()

const commonConfig = {
  network,
  logger: Config.logger(true)
}

const config = Config.gen(
  {app: dna, bob: dna},
  commonConfig
)

orchestrator.registerScenario("Behavior: Can commit an entry then get", async (s, t) => {
  const duration = 5000
  const multiplier = 0.5
  const init = () => s.players({ alice: config }, true)
  const stage = async ({alice, bob}, {period}) => {
    // Run the provided closure for `duration` ms, once every `period` ms
    await periodically({duration, period}, async () => {
      const result = await alice.call("app", "main", "commit_entry", { content: "entry content ..." })
      console.log(result)
      t.ok(result.Ok)

      await s.consistency()

      const get_result = await bob.call("app", "main", "get_entry", { address: result.Ok })
      console.log(get_result)
      t.deepEqual(get_result.Ok.App[1], "entry content ...")
    })
    return {alice, bob}
  }

  // Run the main machinery.
  // 0. run `init` and pass the
  await parameterizedStages({
    init, stage,
    fail: t.fail,
    parameters: {
      // period starts at 1000 and changes by `multiplier` each step
      // e.g. with multipler == 0.5, the period halves at every stage
      period: t => 1000 * Math.pow(multiplier, t),
    }
  })
})

orchestrator.run()