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

happn-random-activity-generator

v0.2.1

Published

generates random activity

Downloads

20

Readme

random activity generator

takes a happn client at construction time, and performs random activities against the clients happn server. highly configurable - allows for the percentage of gets, sets, removes and ons to be configured. For ons, gets and removes some initial data needs to be created - this is also configurable

quickstart:

npm install happn-random-activity-generator --save-dev

configuration:

var RandomActivity = require('happn-random-activity-generator');

//the options are the second parameter - the amounts are the default amounts
generator = new RandomActivity(happnClientInstance, {
	interval:20,//in milliseconds, the interval between each new random call
	percentageGets:[0,20],//range out of 100 of gets that are randomly chosen
	percentageSets:[20,80],//range out of 100 of sets that are randomly chosen
	percentageRemoves:[80,90],//range out of 100 of removes that are randomly chosen
	percentageOns:[90,100],//range out of 100 of ons that are randomly chosen
	initialDataRemoveCount:40,//initial data generated for remove calls
	initialDataOnCount:20,//initial data generated for on calls
	initialDataGetCount:50,//initial data generated for get calls
	randomDataSize:3,//the random data object has a bigData property, this setting creates a string of length (32 * 3)
	onTimeout:100//when the verify operation runs, this is the timeout reached when testing ons
});

start, stop and verify:

when you start the random activity, the timespan it takes to generate the initial data is stored - this is so that when you stop the activity, the system waits for that timespan to actually stop - this allows for accuracy that is not affected by the initialization procedure


var happn = require('happn')
var service = happn.service;
var happn_client = happn.client;

service.create(function(e, instance){
	if (e) return callback(e);
	serviceInstance = instance;

	happn_client.create(function(e, cli){

		if (e) return callback(e);
		clientInstance = cli;

		//instantiate the generator here:
		var RandomActivity = require('happn-random-activity-generator');
		generator = new RandomActivity(clientInstance);

		//start random activity - we use a key "test" to store the generated log data
		//this is so we can run multiple parallel tests if necessary
		generator.generateActivityStart("test", function(e){

			//wait a while, then stop

			setTimeout(function(){

				//end the generation run
				generator.generateActivityEnd("test", function(aggregatedLog){

					//verify the database state matches the logs
					generator.verify(function(e, log){

						callback();
					},
					"test");//verify the "test" group

				});

			}, 2000);

		})
	});
})

replay

you can create 2 generators, have one do a run, then pass it to another generator (perhaps connected to a different db) - its logs is parsed and exactly the same activity is replicated

the following is an example from the test

generator.generateActivityStart("test", function(){
	setTimeout(function(){
		generator.generateActivityEnd("test", function(aggregatedLog){

			var RandomActivity = require('happn-random-activity-generator');
			generator2 = new RandomActivity(clientInstance);
			generator2.replay(generator, "test", function(e, replayLog){

				if (e) return callback(e);

				expect(replayLog.get).to.be(aggregatedLog.get);
				expect(replayLog.set).to.be(aggregatedLog.set);
				expect(replayLog.remove).to.be(aggregatedLog.remove);
				expect(replayLog.on).to.be(aggregatedLog.on);

				callback();

			});

		});

	}, 2000);
});

daemon mode

this is for testing activity over a long period (days/weeks/months), running in this mode does not store a replay log, and only stores aggregated data related to the run

following example from the test


generator.generateActivityStart("test", function(){
	setTimeout(function(){
		generator.generateActivityEnd("test", function(aggregatedLog){
			//expect(generator.__operationLog["test"].length).to.be(0);
			//callback();
			//etc...
		});
	}, 2000);
}, "daemon");//NB here is where you set the mode to "daemon"