node-simleak v0.1.0
simleak
Simleak is a HTTP web service simulator.
Installation
npm install node-simleak
Overview
Simleak is built on top of Connect. It provides a set of features that facilitates web service testing.
- simulates latency by adding delay to requests
- simulates maximum througput by appying throttling
- simulates service errors
- simulates responses with canned content stored in static files
- simulates responses with dynamic content with templates
- proxies requests to remote services
- caches responses for better supporting of load tests
Usage
- Starts simleak service
simleak --config <config_file> --log <log_level>
where config defines the plug-in chain and the configuration of each plug-in in the chain. log defines the logging level of the service.
- Runs tests
make test
- Generates JS documents
make docs
Configuration
The configuration file is itself a JSON object consists of following sections.
service
This section includes configurations related to general service.
local_port
the port number that simleak service will be listeninglog_level the service log level
modules
This section defines the modules that the simleak will load at the start-up time. Each module has an id" which can be referenced later and a path where it can be loaded. simleak* provides a few built-in modules as listed below
- simdelay
- simthrottle
- simerror
- simcache
- simstatic
- simdynamic
- simproxy
- simutil
To load the built-in modules, prefix the module with # such as #simdelay.
One can load any module by providing its loading path and an unique id. To later reference a method from the module in plugins section, use the notion
#module_id.method_name
plugins
This section defines the plug-ins that the simleak will load to form the request process chain.
There are two types of plug-ins. One type only operates on request and passes the request down the chain. They usually don't generate responses (except for generating error responses). Following built-in plug-ins fall into this category:
- simdelay
- simthrottle
- simerror
- simcache
The other type of plug-ins are responsible for creating responses. However, it is possible to have more than one of these plug-ins in the chain. For example, one can config simstatic to serve the static contents and simdynamic to serve the dynamic contents. It is necessary to have one of these plug-ins at the very end of the process chain. Following built-in plug-ins fall into this category:
- simstatic
- simdynamic
- simproxy
The order of the plug-ins matters if there are dependencies among plug-ins. For example, the simcache is designed to work with simstatic and simproxy, it needs to be placed in front of either plug-ins in the chain.
An example configuration can be found under /example which is used to simulate MSN AdCenter APIs.
How to write custom plug-in
A simleak plug-in is just a typical Connect middleware that implements one special method.
module.exports.configure = function(config) {
return function(req, res, next) {
// implementation here
};
};
This method takes a single argument config which is a JSON object defined in the configuration file and returns a process method required by Connect.
simleak provides a few utility methods in simutil. Please refer to the JS documentation for details.
License
MIT License
11 years ago