<commit_before>import shlex, sys, traceback, os, shutil, socket, subprocess, time, signal, threading, random
from vcoptparse import *
from corrupter import *
from rdbstat import *

test_dir_name = "output_from_test"
made_test_dir = False

class TestFailure(Exception):
    def __init__(self, value):
        self.value = value
    def __str__(self):
        return repr(self.value)

def make_test_dir():
    global made_test_dir
    if not made_test_dir:
        if os.path.exists(test_dir_name):
            assert os.path.isdir(test_dir_name)
            shutil.rmtree(test_dir_name)
        os.mkdir(test_dir_name)
        made_test_dir = True
    return test_dir_name

class StdoutAsLog(object):
    def __init__(self, name):
        self.name = name
    def __enter__(self):
        self.path = os.path.join(make_test_dir(), self.name)
        print "Writing log file %r." % self.path
        self.f = file(self.path, "w")
        sys.stdout = self.f
    def __exit__(self, x, y, z):
        sys.stdout = sys.__stdout__
        self.f.close()

def make_option_parser():
    o = OptParser()
    o["auto"] = BoolFlag("--auto")
    o["interactive"] = BoolFlag("--interactive")
    o["database"] = ChoiceFlag("--database", ["rethinkdb", "memcached"], "rethinkdb")
    o["mclib"] = ChoiceFlag("--mclib", ["memcache", "pylibmc"], "pylibmc")
    o["protocol"] = ChoiceFlag("--protocol", ["text", "binary"], "text")
    o["valgrind"] = BoolFlag("--no-valgrind", invert = True)
    o["valgrind-tool"] = StringFlag("--valgrind-tool", "memcheck")
    o["mode"] = StringFlag("--mode", "debug")
    o["netrecord"] = BoolFlag("--no-netrecord", invert = True)
    o["restart_server_prob"] = FloatFlag("--restart-server-prob", 0)
    o["corruption_p"] = FloatFlag("--corruption-p", 0)
    o["cores"] = IntFlag("--cores", 2)
    o["slices"] = IntFlag("--slices", 3)
    o["memory"] = IntFlag("--memory", 100)
    o["duration"] = IntFlag("--duration", 10)
    o["flags"] = StringFlag("--flags", "")
    o["stress"] = StringFlag("--stress", "")
    o["no-timeout"] = BoolFlag("--no-timeout", invert = False)
    o["ssds"] = AllArgsAfterFlag("--ssds", default = [])
    o["mem-cap"] = IntFlag("--mem-cap")
    o["garbage-range"] = MultiValueFlag("--garbage-range", [float_converter, float_converter], default = None)
    return o

# Choose a random port at which to start searching to reduce the probability of collisions
# between different instances of the tests
current_port_to_check = random.randint(5000, 20000)
def find_unused_port():
    global current_port_to_check
    while True:
        current_port_to_check += 1<commit_msg>Made --mem-cap not mandatory.<commit_after>import shlex, sys, traceback, os, shutil, socket, subprocess, time, signal, threading, random
from vcoptparse import *
from corrupter import *
from rdbstat import *

test_dir_name = "output_from_test"
made_test_dir = False

class TestFailure(Exception):
    def __init__(self, value):
        self.value = value
    def __str__(self):
        return repr(self.value)

def make_test_dir():
    global made_test_dir
    if not made_test_dir:
        if os.path.exists(test_dir_name):
            assert os.path.isdir(test_dir_name)
            shutil.rmtree(test_dir_name)
        os.mkdir(test_dir_name)
        made_test_dir = True
    return test_dir_name

class StdoutAsLog(object):
    def __init__(self, name):
        self.name = name
    def __enter__(self):
        self.path = os.path.join(make_test_dir(), self.name)
        print "Writing log file %r." % self.path
        self.f = file(self.path, "w")
        sys.stdout = self.f
    def __exit__(self, x, y, z):
        sys.stdout = sys.__stdout__
        self.f.close()

def make_option_parser():
    o = OptParser()
    o["auto"] = BoolFlag("--auto")
    o["interactive"] = BoolFlag("--interactive")
    o["database"] = ChoiceFlag("--database", ["rethinkdb", "memcached"], "rethinkdb")
    o["mclib"] = ChoiceFlag("--mclib", ["memcache", "pylibmc"], "pylibmc")
    o["protocol"] = ChoiceFlag("--protocol", ["text", "binary"], "text")
    o["valgrind"] = BoolFlag("--no-valgrind", invert = True)
    o["valgrind-tool"] = StringFlag("--valgrind-tool", "memcheck")
    o["mode"] = StringFlag("--mode", "debug")
    o["netrecord"] = BoolFlag("--no-netrecord", invert = True)
    o["restart_server_prob"] = FloatFlag("--restart-server-prob", 0)
    o["corruption_p"] = FloatFlag("--corruption-p", 0)
    o["cores"] = IntFlag("--cores", 2)
    o["slices"] = IntFlag("--slices", 3)
    o["memory"] = IntFlag("--memory", 100)
    o["duration"] = IntFlag("--duration", 10)
    o["flags"] = StringFlag("--flags", "")
    o["stress"] = StringFlag("--stress", "")
    o["no-timeout"] = BoolFlag("--no-timeout", invert = False)
    o["ssds"] = AllArgsAfterFlag("--ssds", default = [])
    o["mem-cap"] = IntFlag("--mem-cap", None)
    o["garbage-range"] = MultiValueFlag("--garbage-range", [float_converter, float_converter], default = None)
    return o

# Choose a random port at which to start searching to reduce the probability of collisions
# between different instances of the tests
current_port_to_check = random.randint(5000, 20000)
def find_unused_port():
    global current_port_to_check
    while True:
        current_port_to_check += 1
{'fraction_non_alphanumeric': 0.16698328267477203, 'fraction_numerical': 0.007218844984802432, 'mean_word_length': 3.480851063829787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5877409', 'n_tokens_mistral': 1826, 'n_tokens_neox': 1764, 'n_words': 387}