mongodb/mongo-ruby-driver — pull request #419 by durran (2014-05-19 14:53:02+00:00)
Title: All hail our testing saviour - the cluster simulator.

When starting to implement the new spec for configuration and monitoring, I realized there would be no easy way to test this without:

1) Banging my head against the wall spinning up replica sets, mongos, and single server setups of various configurations.
2) Slowing the test suite down to a crawl while doing (1) like the 1.x tests do.
3) Not be able to accurately test any sort of failover with respect to not just configuration but network errors, query errors, auth errors, etc.

We handled this in Moped the way I prefer, and I've rewritten that code to take it even further and makes our lives going forward with respect to testing so much easier and having our tests run faster.

To use the cluster simulator in a spec, simply add the macro `simulator: 'cluster'` to the spec:

```ruby
context 'when the servers are not equal', simulator: 'cluster' do
let(:other) do
described_class.new(client, ['127.0.0.1:27020'])
end
it 'returns false' do
expect(cluster).to_not eq(other)
end
end
```

What this does is spin up a default cluster (replica set simulator) with 3 default nodes on `127.0.0.1:27018`, `127.0.0.1:27019` and `127.0.0.1:27020`. All requests that happen to these nodes are proxied through to the underlying mongod on `127.0.0.1:27017` with the exception of the `ismaster` command, which returns custom replies based on the configuration.

Access to the simulator is done through the `simulator` method that is automatically included... For right now this is not important until I add the ability to add/remove/step down/etc but I needed the simulator there to get my tests passing for the initial cluster specs since now the server descriptions are initialized on instantiation of a `Server`.

I'll be adding to this as we go, but no more command line spinning up mongod processes going forward - all programatic.