Project

flu_shot

0.0
No commit activity in last 3 years
No release in over 3 years
Chaos Testing tool for Ruby apps
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.17
~> 5.0
~> 1.11.0
>= 0
~> 4.1.0
 Project Readme

FluShot

FluShot is a Chaos Testing tool for Ruby applications. It can inject unusual and unexpected behaviors into your system, like adding extra latency to a network request, simulating infinite loops, raising exceptions.

The project is currently in work in progress

Idea:

First you need to specify the area where the flu shot needs to be injected, in my example it's the user_controller_show point. I also pass the account_id in order to specify a subset of accounts that I use for testing.

class UserController < ApplicationController
  def show
    # Inject some harmful code, the behaviour is specified in the prespcription definition later.
    FluShot.inject(:user_controller_show, {account: current_account})
    
    User.find(params[:user_id])
  end
end

You need to define vaccines that occur different behaviours. Here is an example for adding extra latency on test account in the production environment.

class Latency < FluShot::Vaccine
  label :latency

  def initialize(params = {})
    if params[:account].is_a_test_account?
      sleep(rand(params[:max] - params[:min]) + params[:min])
    end
  end
end

The last step is we need to create a prescription for the user_controller_show and inject the latency vaccine:

FluShot::Prescription.for(:user_controller_show) do |prescription|
  prescription.add(:latency, {min: 1000, max: 3000})
end

Now if you try to call Users#show action on a test account then you should see 1-3 seconds latency. To reset the latency you need to create a prescription with empty body:

FluShot::Prescription.for(:user_controller_show) do |prescription|
end

Installation

Add this line to your application's Gemfile:

gem 'flu_shot'

And then execute:

$ bundle

Or install it yourself as:

$ gem install flu_shot

Usage

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/nucc/flu_shot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the FluShot project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.