Example #1
0
    def sub_test(self):
        global close, timeout, counter_opener, counter_receiver

        self.server = StorjNet(None, 0, False)
        self.serverNG = StorjNet(None, 0, False, ChannelReceiverNG1)
        self.client = StorjNet(None, 0, False)
        self.m1 = StorjNet('id.json', 0, False)
        self.m2 = StorjNet(None, 0, False)
        self.m3 = StorjNet(None, 0, True)

        self.m4 = StorjNet('id.json', 0, False)
        assert self.m1.mynode.public == self.m4.mynode.public
        assert self.m1.mynode.private == self.m4.mynode.private

        id = self.m2.get_my_id()
        assert len(id) == 52
        logging.debug("id=" + id)
        self.location = self.m2.get_my_location()
        logging.debug("location=" + self.location)
        self.status2 = 0
        self.status4 = 0

        with pytest.raises(TypeError):
            self.m3.open_channel(self.location, 'counter_test', ChannelOpener)

        self.m3.ping(self.location)
        loc = json.loads(self.m3.get_my_location())
        assert len(loc['ip']) > 8
        time.sleep(5)

        self.status = 0
        self.m2.add_channel_handler('counter_test',
                                    (lambda: ChannelReceiver()))
        self.m3.open_channel(self.location, 'counter_test', ChannelOpener())
        time.sleep(5)
        assert counter_opener == 4
        assert counter_receiver == 3

        timeout = False
        close = False
        self.m2.add_channel_handler('counter_testNG', ChannelReceiverNG)
        co = ChannelOpener()
        self.m3.open_channel(self.location, 'counter_testNG', co)
        time.sleep(5)
        assert close
        assert co.close

        timeout = False
        close = False
        self.m2.add_channel_handler('no_response',
                                    ChannelReceiver)
        co = ChannelOpenerNoResponse()
        self.m3.open_channel(self.location, 'no_response', co)
        time.sleep(5)
        assert close
        assert co.close

        timeout = False
        close = False
        co = ChannelOpenerWait()
        self.m3.open_channel(self.location, 'counter_test', co)
        time.sleep(75)
        assert close
        assert co.close
        assert co.nnn == 0

        with pytest.raises(TypeError):
            self.m2.get_channel_handler("nothing")

        self.m2.add_channel_handler('testtest', (lambda: None))
        co = ChannelOpener()
        self.m3.open_channel(self.location, 'testtest', co)
        time.sleep(5)
        assert co.close
Example #2
0
class TestStorjNet(object):

    def sub_error_test(self):
        timeout = False
        close = False
        location = self.server.get_my_location()

        self.server.add_channel_handler('counter_test',
                                        ChannelReceiver)
        co = ChannelOpener()
        self.client.open_channel(location, 'counter_test', co,
                                 ChannelOpenerProtocolNG1)
        time.sleep(5)
        assert co.close

        co = ChannelOpener()
        self.client.open_channel(location, 'counter_test', co,
                                 ChannelOpenerProtocolNG2)
        time.sleep(5)
        assert co.close

        co = ChannelOpener()
        self.client.open_channel(location, 'counter_test', co,
                                 ChannelOpenerProtocolNG3)
        time.sleep(5)
        assert co.close

        co = ChannelOpener()
        self.client.open_channel(location, 'noname', co)
        time.sleep(5)
        assert co.close

        self.serverNG.add_channel_handler('counter_test',
                                          ChannelReceiver)
        location = self.serverNG.get_my_location()
        co = ChannelOpener()
        self.client.open_channel(location, 'counter_test', co)
        time.sleep(5)
        assert co.close

        loc = json.loads(location)
        loc['ip'] = '111.111.111.111'
        co = ChannelOpener()
        self.client.open_channel(json.dumps(loc), 'counter_test', co)
        time.sleep(70)
        assert co.fail

    def sub_test(self):
        global close, timeout, counter_opener, counter_receiver

        self.server = StorjNet(None, 0, False)
        self.serverNG = StorjNet(None, 0, False, ChannelReceiverNG1)
        self.client = StorjNet(None, 0, False)
        self.m1 = StorjNet('id.json', 0, False)
        self.m2 = StorjNet(None, 0, False)
        self.m3 = StorjNet(None, 0, True)

        self.m4 = StorjNet('id.json', 0, False)
        assert self.m1.mynode.public == self.m4.mynode.public
        assert self.m1.mynode.private == self.m4.mynode.private

        id = self.m2.get_my_id()
        assert len(id) == 52
        logging.debug("id=" + id)
        self.location = self.m2.get_my_location()
        logging.debug("location=" + self.location)
        self.status2 = 0
        self.status4 = 0

        with pytest.raises(TypeError):
            self.m3.open_channel(self.location, 'counter_test', ChannelOpener)

        self.m3.ping(self.location)
        loc = json.loads(self.m3.get_my_location())
        assert len(loc['ip']) > 8
        time.sleep(5)

        self.status = 0
        self.m2.add_channel_handler('counter_test',
                                    (lambda: ChannelReceiver()))
        self.m3.open_channel(self.location, 'counter_test', ChannelOpener())
        time.sleep(5)
        assert counter_opener == 4
        assert counter_receiver == 3

        timeout = False
        close = False
        self.m2.add_channel_handler('counter_testNG', ChannelReceiverNG)
        co = ChannelOpener()
        self.m3.open_channel(self.location, 'counter_testNG', co)
        time.sleep(5)
        assert close
        assert co.close

        timeout = False
        close = False
        self.m2.add_channel_handler('no_response',
                                    ChannelReceiver)
        co = ChannelOpenerNoResponse()
        self.m3.open_channel(self.location, 'no_response', co)
        time.sleep(5)
        assert close
        assert co.close

        timeout = False
        close = False
        co = ChannelOpenerWait()
        self.m3.open_channel(self.location, 'counter_test', co)
        time.sleep(75)
        assert close
        assert co.close
        assert co.nnn == 0

        with pytest.raises(TypeError):
            self.m2.get_channel_handler("nothing")

        self.m2.add_channel_handler('testtest', (lambda: None))
        co = ChannelOpener()
        self.m3.open_channel(self.location, 'testtest', co)
        time.sleep(5)
        assert co.close

    def test_storjnet(self):
        if os.path.exists('id.json'):
            os.unlink('id.json')
        self.sub_test()
        self.sub_error_test()

        self.m3.finalize()