Example #1
0
    def testTraySpawning(self):
        self.assertFalse(self.trayIsRunning())
        db_file = os.path.join(os.path.dirname(__file__), 'testfiles', 'tmp_openport.db')
        try:
            os.remove(db_file)
        except OSError:
            pass

        port = get_open_port()

        os.chdir(os.path.dirname(os.path.dirname(__file__)))
        p_app = subprocess.Popen(['env/bin/python', 'apps/openport_app.py', '--local-port', '%s' % port, '--no-gui',
                                  '--verbose'],
                                    stderr=subprocess.PIPE, stdout=subprocess.PIPE)
        self.processes_to_kill.append(p_app)
        sleep(5)
        process_output = nonBlockRead(p_app.stdout)
        print lineNumber(), 'output: ', process_output

        self.check_application_is_still_alive(p_app)
        self.assertTrue(self.trayIsRunning())

        remote_host, remote_port = self.getRemoteHostAndPort(process_output)
        print lineNumber(), "remote port:", remote_port

        os.kill(p_app.pid, signal.SIGKILL)
        p_app.wait()
        sleep(1)
        self.assertTrue(self.trayIsRunning())
        self.killTray()
        self.assertFalse(self.trayIsRunning())
Example #2
0
 def killTray(self):
     url = 'http://localhost:8001/exit'
     try:
         req = urllib2.Request(url)
         response = urllib2.urlopen(req, timeout=1).read()
         if response.strip() != 'ok':
             print lineNumber(), response
     except Exception, detail:
         print detail
Example #3
0
 def trayIsRunning(self):
     url = 'http://localhost:8001/ping'
     try:
         req = urllib2.Request(url)
         response = urllib2.urlopen(req, timeout=5).read()
         if response.strip() != 'pong':
             print lineNumber(), response
             return False
         else:
             return True
     except Exception, detail:
         return False
Example #4
0
    def testTray(self):
        db_file = os.path.join(os.path.dirname(__file__), 'testfiles', 'tmp_openport.db')
        try:
            os.remove(db_file)
        except OSError:
            pass

        port = get_open_port()
        print 'localport :', port
        s = SimpleTcpServer(port)
        s.runThreaded()

        os.chdir(os.path.dirname(os.path.dirname(__file__)))
        p_tray = subprocess.Popen(['env/bin/python', 'tray/openporttray.py', '--no-gui', '--database', db_file],
            stderr=subprocess.PIPE, stdout=subprocess.PIPE)
        p_app = subprocess.Popen(['env/bin/python', 'apps/openport_app.py', '--local-port', '%s' % port, '--no-gui',
                                  '--no-tray', '--verbose'],
            stderr=subprocess.PIPE, stdout=subprocess.PIPE)
        self.processes_to_kill.append(p_tray)
        self.processes_to_kill.append(p_app)
        sleep(10)

        process_output = nonBlockRead(p_app.stdout)
        print lineNumber(), 'output: ', process_output

        self.check_application_is_still_alive(p_tray)
        self.check_application_is_still_alive(p_app)

        remote_host, remote_port = self.getRemoteHostAndPort(process_output)
        print lineNumber(), "remote port:", remote_port

        c = SimpleTcpClient(remote_host, remote_port)
        request = 'hello'
        response = c.send(request)
        self.assertEqual(request, response.strip())
        c.close()
   #     s.close()

        os.kill(p_app.pid, signal.SIGKILL)
        self.assertNotEqual(p_app.wait(), None)
        while self.osinteraction.pid_is_running(p_app.pid):
            print "waiting for pid to be killed: %s" % p_app.pid
            sleep(1)
        os.kill(p_tray.pid, signal.SIGINT)
        print 'waiting for tray to be killed'
        p_tray.wait()
        print lineNumber(),  "tray.stdout:", nonBlockRead(p_tray.stdout)
        print lineNumber(),  "tray.stderr:", nonBlockRead(p_tray.stderr)

        print lineNumber(),  "p_app stdout:", nonBlockRead(p_app.stdout)

        sleep(5)

  #      s = SimpleTcpServer(port)
  #      s.runThreaded()

        p_tray2 = subprocess.Popen(['env/bin/python', 'tray/openporttray.py', '--no-gui', '--database', db_file, '--verbose'],
            stderr=subprocess.PIPE, stdout=subprocess.PIPE)
        self.processes_to_kill.append(p_tray2)
        sleep(10)

        print lineNumber(),  "tray.stdout:", nonBlockRead(p_tray2.stdout)
        print lineNumber(),  "tray.stderr:",nonBlockRead(p_tray2.stderr)
        self.check_application_is_still_alive(p_tray2)

        c = SimpleTcpClient(remote_host, remote_port)
        request = 'hello'
        response = c.send(request)
        self.assertEqual(request, response.strip())

        os.kill(p_tray2.pid, signal.SIGINT)
        p_tray2.wait()
        print lineNumber(),  "tray.stdout:", nonBlockRead(p_tray2.stdout)
        print lineNumber(),  "tray.stderr:",nonBlockRead(p_tray2.stderr)

        response = c.send(request)
        self.assertNotEqual(request, response.strip())

        c.close()
        s.close()