def test_double_b_alt_successful_transfer(self): ch = self.chan() def thread(): ch.b_put(c.b_alt([ch, 'success'])) threading.Thread(target=thread).start() self.assertEqual(c.b_alt(ch), ('success', ch)) self.assertEqual(ch.b_get(), (True, ch))
def test_multiple_successful_get_on_initial_request(self): successGetCh = self.chan() cancelGetCh = self.chan() cancelPutCh = self.chan() successGetCh.f_put('success') time.sleep(0.1) self.assertEqual( c.b_alt(cancelGetCh, successGetCh, [cancelPutCh, 'noSend'], priority=True), ('success', successGetCh)) self._confirm_chs_not_closed(successGetCh, cancelGetCh, cancelPutCh)
def test_close_before_put(self): closedPutCh = self.chan(1) cancelPutCh = self.chan(1) cancelPutCh.b_put('fill buffer') cancelGetCh = self.chan(1) closedPutCh.close() self.assertEqual( c.b_alt(cancelGetCh, [closedPutCh, 'noSend'], [cancelPutCh, 'noSend'], priority=True), (False, closedPutCh)) self.assertIsNone(closedPutCh.b_get())
def test_multiple_successful_get_on_initial_request(self): successGetCh = self.chan(1) successGetCh.b_put('success') cancelGetCh = self.chan(1) cancelPutCh = self.chan(1) cancelPutCh.b_put('fill buffer') self.assertEqual( c.b_alt(cancelGetCh, successGetCh, [cancelPutCh, 'noSend'], priority=True), ('success', successGetCh))
def test_single_successful_get_on_wait(self): ch = self.chan() def thread(): time.sleep(0.1) ch.f_put('success') ch.f_put('notClosed') threading.Thread(target=thread).start() self.assertEqual(c.b_alt(ch), ('success', ch)) self.assertEqual(ch.b_get(), 'notClosed')
def test_close_before_put(self): closedPutCh = self.chan() cancelPutCh = self.chan() cancelGetCh = self.chan() closedPutCh.close() self.assertEqual( c.b_alt(cancelGetCh, [closedPutCh, 'noSend'], [cancelPutCh, 'noSend'], priority=True), (False, closedPutCh)) self.assertIsNone(closedPutCh.b_get()) self._confirm_chs_not_closed(cancelPutCh, cancelGetCh)
def test_multiple_successful_put_on_intial_request(self): successPutCh = self.chan(1) cancelGetCh = self.chan(1) cancelPutCh = self.chan(1) cancelPutCh.b_put('fill buffer') altValue = c.b_alt(cancelGetCh, [cancelPutCh, 'noSend'], [successPutCh, 'success'], priority=True) self.assertEqual(altValue, (True, successPutCh)) self.assertEqual(successPutCh.b_get(), 'success')
def test_multiple_successful_get_on_wait(self): successGetCh = self.chan(1) cancelGetCh = self.chan(1) cancelPutCh = self.chan(1) cancelPutCh.b_put('fill buffer') def thread(): time.sleep(0.1) successGetCh.b_put('success') threading.Thread(target=thread).start() self.assertEqual( c.b_alt(cancelGetCh, successGetCh, [cancelPutCh, 'noSend'], priority=True), ('success', successGetCh))
def test_xform_state_is_not_modified_when_canceled(self): xformCh = self.chan(1, xf.take(2)) xformCh.b_put('firstTake') ch = self.chan() def thread(): time.sleep(0.1) ch.b_put('altValue') threading.Thread(target=thread).start() self.assertEqual( c.b_alt(ch, [xformCh, 'do not modify xform state'], priority=True), ('altValue', ch)) xformCh.f_put('secondTake') xformCh.f_put('dropMe') self.assertEqual(b_list(xformCh), ['firstTake', 'secondTake'])
def test_close_while_waiting_get(self): closeGetCh = self.chan() cancelGetCh = self.chan() cancelPutCh = self.chan() def thread(): time.sleep(0.1) closeGetCh.close() threading.Thread(target=thread).start() self.assertEqual( c.b_alt(cancelGetCh, closeGetCh, [cancelPutCh, 'noSend'], priority=True), (None, closeGetCh)) self.assertIsNone(closeGetCh.b_get()) self._confirm_chs_not_closed(cancelPutCh, cancelGetCh)
def test_close_while_waiting_put(self): closePutCh = self.chan(1) closePutCh.b_put('fill buffer') cancelGetCh = self.chan(1) cancelPutCh = self.chan(1) cancelPutCh.b_put('fill buffer') def thread(): time.sleep(0.1) closePutCh.close() closePutCh.b_get() threading.Thread(target=thread).start() self.assertEqual( c.b_alt(cancelGetCh, [closePutCh, 'success'], [cancelPutCh, 'noSend'], priority=True), (True, closePutCh)) self.assertEqual(closePutCh.b_get(), 'success') self.assertIsNone(closePutCh.b_get())
def thread(): successPutCh.b_put( c.b_alt(cancelGetCh, [successPutCh, 'success'], [cancelPutCh, 'noSend'], priority=True))
def test_b_alt_default_when_available(self): ch = chan(1) ch.b_put('success') self.assertEqual(c.b_alt(ch, default='ignore me'), ('success', ch))
def test_single_successful_get_on_initial_request(self): ch = self.chan() ch.f_put('success') ch.f_put('notClosed') self.assertEqual(c.b_alt(ch), ('success', ch)) self.assertEqual(ch.b_get(), 'notClosed')
def test_no_operations(self): with self.assertRaises(ValueError): c.b_alt()
def thread(): time.sleep(0.1) ch.b_put(c.b_alt([ch, 'success']))
def thread(): ch.b_put(c.b_alt([ch, 'success']))
def test_get_put_same_channel(self): ch = self.chan() with self.assertRaises(ValueError): c.b_alt(ch, [ch, 'success'], priority=True)
def test_double_b_alt_successful_transfer(self): ch = self.chan(1) self.assertEqual(c.b_alt([ch, 'success']), (True, ch)) self.assertEqual(c.b_alt(ch), ('success', ch))
def test_b_alt_default_when_unavailable(self): ch = chan() self.assertEqual(c.b_alt(ch, default='success'), ('success', 'default'))