blob: 3ea5a8e50c019123d07a248b55a5dd46e2786085 [file] [log] [blame]
David Shrewsburyeb856472017-04-13 14:23:04 -04001#!/usr/bin/env python
2
3# Copyright 2017 Red Hat, Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17import logging
18import socket
19import tempfile
20
21import zuul.lib.log_streamer
22import tests.base
23
24
25class TestLogStreamer(tests.base.BaseTestCase):
26
27 log = logging.getLogger("zuul.test.cloner")
28
29 def setUp(self):
30 super(TestLogStreamer, self).setUp()
31 self.host = '0.0.0.0'
32
33 def startStreamer(self, port, root=None):
34 if not root:
35 root = tempfile.gettempdir()
36 return zuul.lib.log_streamer.LogStreamer(None, self.host, port, root)
37
38 def test_start_stop(self):
39 port = 7900
40 streamer = self.startStreamer(port)
41 self.addCleanup(streamer.stop)
42
43 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
44 self.addCleanup(s.close)
45 self.assertEqual(0, s.connect_ex((self.host, port)))
46 s.close()
47
48 streamer.stop()
49
50 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
51 self.addCleanup(s.close)
52 self.assertNotEqual(0, s.connect_ex((self.host, port)))
53 s.close()