예제 #1
0
 def signal_handler(dummy1, dummy2):
     sys.stderr.write("Timeout reached trying to shut down. Force killing...\n")
     sys.stderr.flush()
     if retval:
         os.DMWM_REAL_EXIT(0)
     else:
         os.DMWM_REAL_EXIT(1)
예제 #2
0
 def trapExit(code):
     """
     Cherrypy likes to call os._exit() which causes the interpreter to
     bomb without a chance of catching it. This sucks. This function
     will replace os._exit() and throw an exception instead
     """
     if hasattr(threading.local(), "isMain") and threading.local().isMain:
         # The main thread should raise an exception
         sys.stderr.write("*******EXIT WAS TRAPPED**********\n")
         raise RuntimeError("os._exit() was called in the main thread")
     elif "DONT_TRAP_EXIT" in os.environ:
         # We trust this component to run real exits
         os.DMWM_REAL_EXIT(code)
     else:
         # os._exit on child threads should just blow away the thread
         raise SystemExit("os._exit() was called in a child thread. " + \
                          "Protecting the interpreter and trapping it")
예제 #3
0
        def run(self):

            # trap os._exit
            os.DMWM_REAL_EXIT = os._exit
            os._exit = trapExit
            threading.local().isMain = True

            testPath = 'test/python'
            if self.testCertainPath:
                print("Using the tests below: %s" % self.testCertainPath)
                testPath = self.testCertainPath
            else:
                print("Nose is scanning all tests")

            if self.quickTestMode:
                quickTestArg = ['--stop']
            else:
                quickTestArg = []

            if self.reallyDeleteMyDatabaseAfterEveryTest:
                print("#### WE ARE DELETING YOUR DATABASE. 3 SECONDS TO CANCEL ####")
                print("#### buildbotmode is %s" % self.buildBotMode)
                sys.stdout.flush()
                import WMQuality.TestInit
                WMQuality.TestInit.deleteDatabaseAfterEveryTest("I'm Serious")
                time.sleep(4)
            if self.workerNodeTestsOnly:
                args = [__file__, '--with-xunit', '-m', '(_t.py$)|(_t$)|(^test)', '-a', 'workerNodeTest',
                        self.testingRoot]
                args.extend(quickTestArg)
                retval = self.callNose(args, paths=testPath)
            elif not self.buildBotMode:
                args = [__file__, '--with-xunit', '-m', '(_t.py$)|(_t$)|(^test)', '-a', '!workerNodeTest',
                        self.testingRoot]
                args.extend(quickTestArg)
                retval = self.callNose(args, paths=testPath)
            else:
                print("### We are in buildbot mode ###")
                srcRoot = os.path.join(os.path.normpath(os.path.dirname(__file__)), 'src', 'python')
                modulesToCover = []
                modulesToCover.extend(get_subpackages(os.path.join(srcRoot, 'WMCore'), 'WMCore'))
                modulesToCover.extend(get_subpackages(os.path.join(srcRoot, 'WMComponent'), 'WMComponent'))
                modulesToCover.extend(get_subpackages(os.path.join(srcRoot, 'WMQuality'), 'WMQuality'))
                sys.stdout.flush()
                if not quickTestArg:
                    retval = self.callNose([__file__, '--with-xunit', '-m', '(_t.py$)|(_t$)|(^test)', '-a',
                                            '!workerNodeTest,!integration,!performance,!lifecycle,!__integration__,!__performance__,!__lifecycle__',
                                            #  '--with-coverage','--cover-html','--cover-html-dir=coverageHtml','--cover-erase',
                                            #  '--cover-package=' + moduleList, '--cover-inclusive',
                                            testPath],
                                           paths=testPath)
                else:
                    retval = self.callNose([__file__, '--with-xunit', '-m', '(_t.py$)|(_t$)|(^test)', '-a',
                                            '!workerNodeTest,!integration,!performance,!lifecycle,!__integration__,!__performance__,!__lifecycle__',
                                            '--stop', testPath],
                                           paths=testPath)

            threadCount = len(threading.enumerate())

            # Set the signal handler and a 20-second alarm
            def signal_handler(dummy1, dummy2):
                sys.stderr.write("Timeout reached trying to shut down. Force killing...\n")
                sys.stderr.flush()
                if retval:
                    os.DMWM_REAL_EXIT(0)
                else:
                    os.DMWM_REAL_EXIT(1)

            signal.signal(signal.SIGALRM, signal_handler)
            signal.alarm(20)
            marker = open("nose-marker.txt", "w")
            marker.write("Ready to be slayed\n")
            marker.flush()
            marker.close()

            if threadCount > 1:
                import cherrypy
                sys.stderr.write(
                    "There are %s threads running. Cherrypy may be acting up.\n" % len(threading.enumerate()))
                sys.stderr.write("The threads are: \n%s\n" % threading.enumerate())
                atexit.register(cherrypy.engine.stop)
                cherrypy.engine.exit()
                sys.stderr.write("Asked cherrypy politely to commit suicide\n")
                sys.stderr.write("Now there are %s threads running\n" % len(threading.enumerate()))
                sys.stderr.write("The threads are: \n%s\n" % threading.enumerate())

            threadCount = len(threading.enumerate())
            print("Testing complete, there are now %s threads" % len(threading.enumerate()))

            # try to exit
            if retval:
                sys.exit(0)
            else:
                sys.exit(1)

            # if we got here, then sys.exit got cancelled by the alarm...
            sys.stderr.write("Failed to exit after 30 secs...something hung\n")
            sys.stderr.write("Forcing process to die")
            os.DMWM_REAL_EXIT()