def test_forever(ns):
    seed = ns['seed']
    bgf_enabled = ns['buggify']
    num_iter = ns['num_iter']

    jj = 0
    okay = True

    gen.global_prng = random.Random(seed)

    (client1, client2, instance) = get_clients(ns['1'], ns['2'], ns)
    # this assumes that the database name we use for testing is "test"
    client = client1 if "doclayer" == ns['1'] else (
        client2 if "doclayer" == ns['2'] else None)
    if client is not None:
        client.test.command("buggifyknobs", bgf_enabled)

    dbName = 'test-' + instance + '-' + str(
        gen.global_prng.randint(100000, 100000000))
    while okay:
        jj += 1
        if num_iter != 0 and jj > num_iter:
            break

        collName = 'correctness-' + instance + '-' + str(
            gen.global_prng.randint(100000, 100000000))
        collection1 = client1[dbName][collName]
        collection2 = client2[dbName][collName]

        print '========================================================'
        print 'PID : ' + str(os.getpid()) + ' iteration : ' + str(
            jj) + ' DB : ' + dbName + ' Collection: ' + collName
        print '========================================================'
        (okay, fname, e) = one_iteration(collection1, collection2, ns, seed)

        if not okay:
            # print 'Seed for failing iteration: ', seed
            fname = util.rename_file(fname, ".failed")
            # print 'File for failing iteration: ', fname
            with open(fname, 'r') as fp:
                for line in fp:
                    print line
            break

        # Generate a new seed and start over
        seed = random.randint(0, sys.maxint)
        gen.global_prng = random.Random(seed)

        # house keeping
        collection1.drop()
        collection2.drop()

    return okay
def test_forever(ns):
    (client1, client2, collection1,
     collection2) = get_clients_and_collections(ns)

    seed = ns['seed']
    bgf_enabled = ns['buggify']
    num_iter = ns['num_iter']

    jj = 0
    okay = True

    gen.global_prng = random.Random(seed)

    # this assumes that the database name we use for testing is "test"
    client = client1 if "doclayer" == ns['1'] else (
        client2 if "doclayer" == ns['2'] else None)
    if client is not None:
        client.test.command("buggifyknobs", bgf_enabled)

    while okay:
        jj += 1
        if num_iter != 0 and jj > num_iter:
            break

        print '========================================================'
        print 'ID : ' + str(os.getpid()) + ' iteration : ' + str(jj)
        print '========================================================'
        (okay, fname, e) = one_iteration(collection1, collection2, ns, seed)

        if not okay and e is not None:
            print "EXCEPTION :", str(e)
            if [
                    x for x in ignored_exceptions
                    if x.strip() == str(e).strip().strip('\"').strip('.')
            ]:
                print "Ignoring EXCEPTION :", str(e)
                okay = True

        if not okay:
            # print 'Seed for failing iteration: ', seed
            fname = util.rename_file(fname, ".failed")
            # print 'File for failing iteration: ', fname
            with open(fname, 'r') as fp:
                for line in fp:
                    print line
            break

        # Generate a new seed and start over
        seed = random.randint(0, sys.maxint)
        gen.global_prng = random.Random(seed)

    return okay
示例#3
0
def test_auto_forever(ns):
    import atexit
    atexit.register(show_statistics, ns)

    # make sure the folder where failure will be stored is created
    global run_path
    run_path = os.path.dirname(os.path.realpath(__file__)) + '/test_results/'
    if not os.path.exists(run_path):
        os.makedirs(run_path)

    # number of minute to run the test
    num_min = ns["num_min"]

    start_time = time.time()

    # number of parallel runs
    num_parallel = ns["num_parallel"]

    # Initialize it with 0 which means auto-generate it
    ns['instance_id'] = 0

    is_time_to_stop = False
    last_update = [None] * num_parallel

    while True:
        try:
            # Why do we need this here ? - if too many tests start to fail, perhaps we should restore it, but
            # commenting it out for now.
            # sleep(0.1)

            # if we cannot create new tests and there are no other active, lets finish
            if is_time_to_stop == True:  # and len(processes) == 0:
                break

            # create initial number of processes
            if not is_time_to_stop and len(processes) == 0:
                for ii in range(min(len(processes), num_parallel), max(len(processes), num_parallel)):
                    start_process(ns)
                    last_update[ii] = time.time()

            for ii, pp in enumerate(processes):
                # if user provided num of min to run, we should check that here
                curr_time = time.time()
                run_min = (curr_time - start_time) / 60

                if 0 < num_min < run_min and is_time_to_stop == False:
                    print "Time to stop, time to run was set to", num_min
                    print "Start time:", time.asctime(time.localtime(start_time))
                    print "Finish time:", time.asctime(time.localtime(curr_time))
                    is_time_to_stop = True

                # if test run did not updated itself in 2 minutes, perhaps it is stuck ?
                stop_unresponsive = ((curr_time - last_update[ii]) / 60) > 2

                if pp.poll() is not None or stop_unresponsive:
                    if stop_unresponsive:
                        fname = run_path + "journal_" + str(instances[ii]) + ".running"
                        fname = util.rename_file(fname, ".timeout")
                        print "Process was stopped because of timeout, check out this file for more info : ", fname
                    kill_process(processes[ii])
                    del processes[ii]
                    del instances[ii]
                    # Start new process only if we are not in time out
                    if not is_time_to_stop:
                        start_process(ns)
                        last_update[ii] = time.time()

                out = non_block_readline(pp.stderr)
                if out != '':
                    last_update[ii] = time.time()
                    sys.stdout.write(out)
                    sys.stdout.flush()

        except Exception as inst:
            print inst
            print "Unexpected error:", sys.exc_info()[0]
            pass
    print "AUTOMATION FINISHED ITS WORK"
示例#4
0
def test_rename_file():
    util.rename_file('a.txt', 'b.txt')