def test_start_stop(self): """Test starting and stopping an instance""" instance = MongoInstance(10101) self.assertTrue(instance.conn.alive()) instance.terminate() self.assertFalse(instance.conn.alive())
def test_multiple_instances(self): """Test we can start multiple instance, but not with the same name""" inst1 = MongoInstance(10101) inst2 = MongoInstance(10102) self.assertRaises(ProcessRunningError, lambda: MongoInstance(10101)) inst1.terminate() inst2.terminate()
def test_flush(self): """Test flushing the instance""" instance = MongoInstance(10101) collection = instance.conn['someDb']['someCollection'] collection.insert({'foo': 'bar'}) self.assertEqual( collection.find({'foo': 'bar'}).next()['foo'], 'bar' ) instance.flush() self.assertEqual(collection.find({'foo': 'bar'}).count(), 0) instance.terminate()
def test_cleanup(self): """Test _cleanup kills all instance kinds""" redis = RedisInstance(10101) mongo = MongoInstance(10102) self.assertEqual(len(managed_instance.running_instances), 2) managed_instance._cleanup(exiting=True) self.assertEqual(len(managed_instance.running_instances), 0) self.assertFalse(os.path.exists(managed_instance.instance_tmpdir)) # It's module-wide so reset this for future tests managed_instance.instance_tmpdir = tempfile.mkdtemp()
def test_flush(self): """Test flushing the instance""" instance = MongoInstance(10101) collection = instance.conn['someDb']['someCollection'] collection.insert({'foo': 'bar'}) self.assertEqual(collection.find({'foo': 'bar'}).next()['foo'], 'bar') instance.flush() self.assertEqual(collection.find({'foo': 'bar'}).count(), 0) instance.terminate()
def test_get_logs(self): """Test getting the instance logs""" instance = MongoInstance(10101) logs = instance.get_logs() self.assertGreater(len(logs), 1000) instance.terminate()
def test_gevent(self): """Test starting mongo with gevent.""" instance = MongoInstance(10101, use_gevent=True) self.assertEqual(len(managed_instance.running_instances), 1) instance.flush() instance.terminate()
def test_failure(self, *args): """Test an instance that refuses to start""" self.assertRaises(ProcessNotStartingError, lambda: MongoInstance(10101))