@avital/meteor-down
Load testing for Meteor
Last updated 4 years ago by avital .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @avital/meteor-down 
SYNC missed versions from official npm registry.

MeteorDown Build Status

MeteorDown is a load testing tool for Meteor server side components. It uses the DDP protocol to communicate with the Meteor application. You can write your load test in JavaScript and let MeteorDown to invoke it.

Installation

Create a file called my_load_test.js with the following content:

var meteorDown = require('@avital/meteor-down');

meteorDown.init(function (Meteor) {
  Meteor.call('example-method', function (error, result) {
    Meteor.kill();
  });
});

meteorDown.run({
  concurrency: 10,
  url: "http://localhost:3000"
});

Then run your script:

node my_load_test.js

Client API

With the MeteorDown script, you can call methods and invoke subscriptions. The function given to meteorDown.init will receive the ddp client as the first argument.

This ddp client is based on node-ddp-client but with some changes to make it more Meteor like. Let's look at APIs:

###Meteor.call

Meteor.call('name'[, args*], callback)

Call a Meteor method. Just like the browser client, the callback will receive 2 arguments Error and the Result.

###Meteor.subscribe

Meteor.subscribe('name'[, args*], callback)

The callback function will be called when the subscription is ready and all initial data is loaded to the client.

###Meteor.kill

Meteor.kill()

Disconnect the current client from the server. As soon as this is called, another client will connect to the server and run load test code.

###Meteor.collections

var Collection = Meteor.collections['name']

A dictionary of all client side collections. Data received from subscriptions will be available here.

Authentication

Normally, most of the Meteor methods and subscriptions are only available for loggedIn users. So, we can't directly invoke those methods and subscriptions. MeteorDown has a solution for that.

First you need to install the following package:

meteor add meteorhacks:meteor-down

Then you need to start your Meteor app with a key. That could be anything you like. But it's better to have a hard to guess key.

export METEOR_DOWN_KEY='YOUR_SUPER_SECRET_KEY'
meteor

Now, add that key to your MeteorDown script and tell which users you need to authenticated against the load test. This is how you can do it.

meteorDown.run({
  concurrency: 10,
  url: "http://localhost:3000",
  key: 'YOUR_SUPER_SECRET_KEY',
  auth: {userIds: ['JydhwL4cCRWvt3TiY', 'bg9MZZwFSf8EsFJM4']}
})

Then all your method calls and subscriptions will be authenticated for one of the user mentioned above.

You can also get the loggedIn user's userId by invoking Meteor.userId() as shown below:

meteorDown.init(function (Meteor) {
  console.log("userId is:", Meteor.userId());
})

Options

All test options are optional therefor it's perfectly okay to call mdown.run without any arguments. All available arguments and their default values are given below.

meteorDown.run({
  concurrency: 10,
  url: 'http://localhost:3000',
  key: undefined,
  auth: undefined
});

concurrency

The maximum number of clients connects to the application at any given time. The real number of concurrent connections can be lower than this number.

url

Meteor application url. NOTE: This should only have the domain and the port (example: localhost:3000). Meteor-down does not support routes at the moment.

key

The secret key to use for MeteorDown authentication.

auth

Authentication information. Currently MeteorDown only supports login by userId.

Examples

Calling a Method

// Meteor Application
Meteor.methods({
  add: function (x, y) {return x + y }
})
// MeteorDown Script
meteorDown.init(function (Meteor) {
  Meteor.call('add', 5, 6, function (err, res) {
    console.log('5 + 6 is ' + res);
    Meteor.kill();
  });
})

Subscribing

// Meteor Application
Items = new Meteor.Collection('items');
Meteor.publish({
  allitems: function () { return Items.find() }
})
// MeteorDown Script
meteorDown.init(function (Meteor) {
  Meteor.subscribe('allitems', function () {
    console.log('Subscription is ready');
    console.log(Meteor.collections.items);
    Meteor.kill();
  });
})

Current Tags

  • 2.6.1                                ...           latest (4 years ago)

1 Versions

  • 2.6.1                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 2
Dependencies (3)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |