def test_MultipleChunk_SingleThen_YieldAsyncErrorMiddleman(self): expected = [ lambda r: self.assertRaises(Exception, r.get), lambda r: self.assertRaises(Exception, r.get), lambda r: self.assertRaises(Exception, r.get), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) def middleMan(result): result.get() s1 = yield ServiceMock(chunks=[4, Exception(), 6], T=self.T, ioLoop=self.io_loop, interval=0.001).execute() # Here exception comes s2 = yield s3 = yield print('This should not be seen!', s1, s2, s3) yield 1 f = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_YieldAsyncMiddlemanExtraChunksResultsInChokeEventForever(self): expected = [ lambda r: self.assertRaises(ChokeEvent, r.get), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) def middleMan(result): result.get() s1 = yield ServiceMock(chunks=[4, 5], T=self.T, ioLoop=self.io_loop, interval=0.001).execute() s2 = yield # This one will lead to the ChokeEvent s3 = yield s4 = yield yield [s1, s2, s3, s4] f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop, interval=0.01).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_SingleChunk_SingleThen(self): expected = [lambda r: self.assertEqual(1, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get)] check = checker(expected, self) f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute() f.then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_SingleChunk_SingleThen_YieldAsyncDoubleMiddlemanWithMoreChunks( self): expected = [ lambda r: self.assertEqual([4, 5, 6, 7, 8], r.get()), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) def middleMan(result): result.get() s1 = yield ServiceMock(chunks=[4, 5], T=self.T, ioLoop=self.io_loop, interval=0.001).execute() s2 = yield s3 = yield ServiceMock(chunks=[6, 7, 8], T=self.T, ioLoop=self.io_loop, interval=0.001).execute() s4 = yield s5 = yield yield [s1, s2, s3, s4, s5] f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop, interval=0.01).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_MultipleChunk_SingleThen_YieldAsyncMiddleman(self): expected = [ lambda r: self.assertEqual([1, 2], r.get()), lambda r: self.assertEqual([2, 3], r.get()), lambda r: self.assertEqual([3, 4], r.get()), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) def middleMan(result): r = result.get() s1 = yield ServiceMock(chunks=[r, r + 1], T=self.T, ioLoop=self.io_loop, interval=0.001).execute() s2 = yield yield [s1, s2] f = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop, interval=0.01).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_SingleChunk_SingleThen(self): expected = [ lambda r: self.assertEqual(1, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute() f.then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_GetMultipleMixChunksWithComplexChain(self): def middleMan(result): r = result.get() if r == 2: raise Exception('=(') yield r f = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop).execute() f.then(middleMan) self.assertEqual(1, f.get()) self.assertRaises(Exception, f.get) self.assertEqual(3, f.get())
def test_SingleChunk_MultipleThen_Middleman(self): expected = [lambda r: self.assertEqual(2, r.get())] check = checker(expected, self) def middleMan(result): return result.get() + 1 f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute() f.then(middleMan).then(check) self.wait(timeout=0.5) self.assertTrue(len(expected) == 0)
def test_SingleChunk_MultipleThen_ErrorMiddleman(self): expected = [lambda r: self.assertRaises(ValueError, r.get), lambda r: self.assertRaises(ValueError, r.get)] check = checker(expected, self) def middleMan(result): raise ValueError("Middleman") f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_SingleChunk_MultipleThen(self): expected = [lambda r: self.assertEqual(2, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get)] check = checker(expected, self) f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute() def firstStep(futureResult): r = futureResult.get() return r * 2 f.then(firstStep).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_SingleChunk_SingleThen_YieldMiddleman(self): expected = [lambda r: self.assertEqual(3, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get)] check = checker(expected, self) def middleMan(result): result.get() yield "String that won't be seen by anyone" yield 3 f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_GetMultipleMixChunksWithComplexChain(self): def middleMan(result): r = result.get() if r == 2: raise Exception('=(') yield r f = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop).execute() f.then(middleMan) self.assertEqual(1, f.get()) self.assertRaises(Exception, f.get) self.assertEqual(3, f.get())
def test_SingleChunk_MultipleThen_Middleman(self): expected = [ lambda r: self.assertEqual(2, r.get()), ] check = checker(expected, self) def middleMan(result): return result.get() + 1 f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute() f.then(middleMan).then(check) self.wait(timeout=0.5) self.assertTrue(len(expected) == 0)
def test_SingleChunk_MultipleThen_ErrorMiddleman(self): expected = [ lambda r: self.assertRaises(ValueError, r.get), lambda r: self.assertRaises(ValueError, r.get), ] check = checker(expected, self) def middleMan(result): raise ValueError('Middleman') f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_SingleChunk_MultipleThen(self): expected = [ lambda r: self.assertEqual(2, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute() def firstStep(futureResult): r = futureResult.get() return r * 2 f.then(firstStep).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_SingleChunk_MultipleChainItems_MixedProcessing2(self): expected = [lambda r: self.assertEqual(6, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get)] check = checker(expected, self) def firstStep(result): yield result.get() * 3 def secondStep(result): r = result.get() return r * 2 f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute() f.then(firstStep).then(secondStep).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_SingleChunk_SingleThen_YieldAsyncDoubleMiddlemanWithLessChunks(self): expected = [lambda r: self.assertEqual([4, 5, 6], r.get()), lambda r: self.assertRaises(ChokeEvent, r.get)] check = checker(expected, self) def middleMan(result): result.get() s1 = yield ServiceMock(chunks=[4, 5], T=self.T, ioLoop=self.io_loop, interval=0.002).execute() s2 = yield s3 = yield ServiceMock(chunks=[6], T=self.T, ioLoop=self.io_loop, interval=0.001).execute() yield [s1, s2, s3] f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop, interval=0.01).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_YieldAsyncMiddlemanExtraChunkResultsInChokeEvent(self): expected = [lambda r: self.assertRaises(ChokeEvent, r.get), lambda r: self.assertRaises(ChokeEvent, r.get)] check = checker(expected, self) def middleMan(result): result.get() s1 = yield ServiceMock(chunks=[4, 5], T=self.T, ioLoop=self.io_loop, interval=0.001).execute() s2 = yield # This one will lead to the ChokeEvent s3 = yield yield [s1, s2, s3] f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop, interval=0.01).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_SingleChunk_SingleThen_YieldMiddleman(self): expected = [ lambda r: self.assertEqual(3, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) def middleMan(result): result.get() yield 'String that won\'t be seen by anyone' yield 3 f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_SingleChunk_MultipleChainItems_OnlyCoroutinesProcessing(self): expected = [lambda r: self.assertEqual(4, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get)] check = checker(expected, self) def firstStep(result): r = result.get() yield "String that won't be seen by anyone" yield r * 2 def secondStep(result): yield result.get() * 2 f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute() f.then(firstStep).then(secondStep).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_MultipleChunk_SingleThen_YieldMiddleman(self): expected = [ lambda r: self.assertEqual(3, r.get()), lambda r: self.assertEqual(6, r.get()), lambda r: self.assertEqual(9, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) def middleMan(result): r = result.get() yield 'This string won\'t be seen by anyone' yield r * 3 f = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_MultipleChunk_SingleThen_YieldAsyncMiddleman(self): expected = [ lambda r: self.assertEqual([1, 2], r.get()), lambda r: self.assertEqual([2, 3], r.get()), lambda r: self.assertEqual([3, 4], r.get()), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) def middleMan(result): r = result.get() s1 = yield ServiceMock(chunks=[r, r + 1], T=self.T, ioLoop=self.io_loop, interval=0.001).execute() s2 = yield yield [s1, s2] f = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop, interval=0.01).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_MultipleChunk_SingleThen_YieldErrorMiddleman(self): expected = [ lambda r: self.assertEqual(1, r.get()), lambda r: self.assertRaises(Exception, r.get), lambda r: self.assertEqual(3, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) def middleMan(result): r = result.get() if r == 2: raise Exception('=(') yield r f = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_SingleChunk_MultipleChainItems_MixedProcessing2(self): expected = [ lambda r: self.assertEqual(6, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) def firstStep(result): yield result.get() * 3 def secondStep(result): r = result.get() return r * 2 f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute() f.then(firstStep).then(secondStep).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_MultipleChunks_MultipleThen_ErrorMiddleman(self): expected = [ lambda r: self.assertEqual(2, r.get()), lambda r: self.assertRaises(ValueError, r.get), lambda r: self.assertEqual(6, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) def middleMan(result): if result.get() == 2: raise ValueError('Middleman') else: return result.get() * 2 f = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_MultipleChunk_MultipleThen_SyncTransformation(self): expected = [ lambda r: self.assertEqual({"app": "info"}, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) def firstStep(result): r = result.get() return {"app": r} def secondStep(result): r = result.get() return r s = ServiceMock(chunks=["info"], T=self.T, ioLoop=self.io_loop).execute() s.then(firstStep).then(secondStep).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_SingleChunk_MultipleChainItems_OnlyCoroutinesProcessing(self): expected = [ lambda r: self.assertEqual(4, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) def firstStep(result): r = result.get() yield 'String that won\'t be seen by anyone' yield r * 2 def secondStep(result): yield result.get() * 2 f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute() f.then(firstStep).then(secondStep).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_MultipleChunk_SingleThen_YieldErrorMiddleman(self): expected = [ lambda r: self.assertEqual(1, r.get()), lambda r: self.assertRaises(Exception, r.get), lambda r: self.assertEqual(3, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) def middleMan(result): r = result.get() if r == 2: raise Exception('=(') yield r f = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_MultipleChunks_MultipleThen_ErrorMiddleman(self): expected = [ lambda r: self.assertEqual(2, r.get()), lambda r: self.assertRaises(ValueError, r.get), lambda r: self.assertEqual(6, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) def middleMan(result): if result.get() == 2: raise ValueError('Middleman') else: return result.get() * 2 f = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_MultipleChunk_MultipleThen_SyncTransformation(self): expected = [ lambda r: self.assertEqual({'app': 'info'}, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) def firstStep(result): r = result.get() return {'app': r} def secondStep(result): r = result.get() return r s = ServiceMock(chunks=['info'], T=self.T, ioLoop=self.io_loop).execute() s.then(firstStep).then(secondStep).then(check) self.wait() self.assertTrue(len(expected) == 0)
def test_MultipleChunk_SingleThen_YieldAsyncErrorMiddleman(self): expected = [ lambda r: self.assertRaises(Exception, r.get), lambda r: self.assertRaises(Exception, r.get), lambda r: self.assertRaises(Exception, r.get), lambda r: self.assertRaises(ChokeEvent, r.get), ] check = checker(expected, self) def middleMan(result): result.get() s1 = yield ServiceMock(chunks=[4, Exception(), 6], T=self.T, ioLoop=self.io_loop, interval=0.001).execute() # Here exception comes s2 = yield s3 = yield print('This should not be seen!', s1, s2, s3) yield 1 f = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop).execute() f.then(middleMan).then(check) self.wait() self.assertTrue(len(expected) == 0)