Example #1
0
    async def test_websocket_server(self):
        port = get_free_tcp_port()
        self.monitor = Monitor([self.datadir], port=port)
        self.monitor.start()

        time.sleep(1)

        ws_url = 'ws://localhost:{}/images'.format(port)
        async with WebSocketClient(ws_url) as ws:
            # Retrieve the starting images, they should be 14 blanks,
            # we ask for 15 and make sure they are actually 14
            l = await ws.get_messages(15, timeout=1)
            assert len(l) == 14
            for image_string in l:
                image = json.loads(image_string)
                assert image['image'] == ''

            # Now trigger the process of a file
            shutil.copy(self.file_empty_init, self.file_empty)

            files = ['latest_0.png', 'latest_1.png']
            look_for_files_or_bust(files, STANDARD_TIMEOUT)

            # Ask the new images
            l = await ws.get_messages(2, timeout=1)
            assert len(l) == 2
            for image_string in l:
                image = json.loads(image_string)
                assert image['index'] in [0, 1]
                compare_images(image['image'],
                               'latest_{}.png'.format(image['index']))

            for fname in files:
                assert os.path.exists(fname)
                os.unlink(fname)
Example #2
0
    def test_polling(self):
        port = get_free_tcp_port()
        self.monitor = Monitor([self.datadir], polling=True, port=port)
        self.monitor.start()

        time.sleep(1)

        shutil.copy(self.file_empty_init, self.file_empty)

        files = ['latest_0.png', 'latest_1.png']
        look_for_files_or_bust(files, STANDARD_TIMEOUT)

        for fname in files:
            os.unlink(fname)
Example #3
0
    def test_a_single_feed(self):
        port = get_free_tcp_port()
        self.monitor = Monitor([self.datadir],
                               config_file=self.config_file,
                               port=port)
        self.monitor.start()

        time.sleep(1)

        shutil.copy(self.file_empty_init_single_feed,
                    self.file_empty_single_feed)

        files = ['latest_10.png']
        look_for_files_or_bust(files, STANDARD_TIMEOUT)

        for fname in files:
            os.unlink(fname)
Example #4
0
    def test_http_server(self):
        port = get_free_tcp_port()
        self.monitor = Monitor([self.datadir], port=port)
        self.monitor.start()

        time.sleep(1)

        shutil.copy(self.file_empty_init, self.file_empty)

        # Check that index.html is provided by the HTTP server
        url = 'http://127.0.0.1:{}/'.format(port)
        r = urllib.request.urlopen(url, timeout=5)
        assert r.code == 200

        files = ['latest_0.png', 'latest_1.png']
        look_for_files_or_bust(files, STANDARD_TIMEOUT)

        for fname in files:
            assert os.path.exists(fname)
            os.unlink(fname)
Example #5
0
    def test_delete_old_images(self):
        files = ['latest_{}.png'.format(i) for i in range(8)]

        for fname in files[2:]:
            sp.check_call('touch {}'.format(fname).split())

        port = get_free_tcp_port()
        self.monitor = Monitor([self.datadir], port=port)
        self.monitor.start()

        time.sleep(1)

        shutil.copy(self.file_empty_init, self.file_empty)

        look_for_files_or_bust(files[:2], STANDARD_TIMEOUT)

        for fname in files[2:]:
            assert not os.path.exists(fname)

        for fname in files[:2]:
            os.unlink(fname)
Example #6
0
    def test_workers(self):
        files = ['latest_8.png', 'latest_10.png']

        port = get_free_tcp_port()
        self.monitor = Monitor([self.datadir],
                               config_file=self.config_file,
                               workers=2,
                               port=port)
        self.monitor.start()

        time.sleep(1)

        shutil.copy(self.file_empty_init_single_feed,
                    self.file_empty_single_feed)
        shutil.copy(self.file_empty_init_single_feed,
                    self.file_empty_single_feed.replace('fits5', 'fits4'))

        look_for_files_or_bust(files, STANDARD_TIMEOUT)

        for i, fname in enumerate(files):
            os.unlink(fname)

        os.unlink(self.file_empty_single_feed.replace('fits5', 'fits4'))