<commit_before>#!/usr/bin/env python2.7
import os
import subprocess
import tempfile
import time
import socket
import sys

tempdir = tempfile.mkdtemp()

def build(path):
    cmd = 'go build -o %s/%s %s' % (tempdir, os.path.basename(path), path)
    print(cmd)
    if subprocess.Popen(cmd, shell=True).wait() != 0:
        sys.exit(1)

# A strange Go bug: If cfssl is up-to-date, we'll get a failure building
# Boulder. Work around by touching cfssl.go.
subprocess.Popen('touch Godeps/_workspace/src/github.com/cloudflare/cfssl/cmd/cfssl/cfssl.go', shell=True).wait()
build('./cmd/boulder')
build('./Godeps/_workspace/src/github.com/cloudflare/cfssl/cmd/cfssl')

boulder = subprocess.Popen('''
    exec %s/boulder --config test/boulder-test-config.json
    ''' % tempdir, shell=True)

cfssl = subprocess.Popen('''
    exec %s/cfssl \
      -loglevel 0 \
      serve \
      -port 9300 \
      -ca test/test-ca.pem \
      -ca-key test/test-ca.key \
      -config test/cfssl-config.json
    ''' % tempdir, shell=True, stdout=None)

def run_test():
    os.chdir('test/js')

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    # Wait up to 7 seconds for Boulder to come up.
    for i in range(0, 7):
        try:
            s.connect(('localhost', 4300))
            break
        except socket.error, e:
            pass
        time.sleep(1)

    issue = subprocess.Popen('''
        node test.js --email <EMAIL> --agree true \
          --domain foo.com --new-reg http://localhost:4300/acme/new-reg \
          --certKey %s/key.pem --cert %s/cert.der
        ''' % (tempdir, tempdir), shell=True)
    if issue.wait() != 0:
        exit(1)
    revoke = subprocess.Popen('''
        node revoke.js %s/cert.der %s/key.pem http://localhost:4300/acme/revoke-cert/
        ''' % (tempdir, tempdir), shell=True)
    if revoke.wait() != 0:
        exit(1)
    print("SUCCESS")

try:
    run_test()
finally:
    boulder.kill()
    cfssl.kill()

<commit_msg>Better cleanup in integration test.<commit_after>#!/usr/bin/env python2.7
import os
import shutil
import socket
import subprocess
import sys
import tempfile
import time

tempdir = tempfile.mkdtemp()

def build(path):
    cmd = 'go build -o %s/%s %s' % (tempdir, os.path.basename(path), path)
    print(cmd)
    if subprocess.Popen(cmd, shell=True).wait() != 0:
        sys.exit(1)

# A strange Go bug: If cfssl is up-to-date, we'll get a failure building
# Boulder. Work around by touching cfssl.go.
subprocess.Popen('touch Godeps/_workspace/src/github.com/cloudflare/cfssl/cmd/cfssl/cfssl.go', shell=True).wait()
build('./cmd/boulder')
build('./Godeps/_workspace/src/github.com/cloudflare/cfssl/cmd/cfssl')

boulder = subprocess.Popen('''
    exec %s/boulder --config test/boulder-test-config.json
    ''' % tempdir, shell=True)

cfssl = subprocess.Popen('''
    exec %s/cfssl \
      -loglevel 0 \
      serve \
      -port 9300 \
      -ca test/test-ca.pem \
      -ca-key test/test-ca.key \
      -config test/cfssl-config.json
    ''' % tempdir, shell=True, stdout=None)

def run_test():
    os.chdir('test/js')

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    # Wait up to 7 seconds for Boulder to come up.
    for i in range(0, 7):
        try:
            s.connect(('localhost', 4300))
            break
        except socket.error, e:
            pass
        time.sleep(1)

    issue = subprocess.Popen('''
        node test.js --email <EMAIL> --agree true \
          --domain foo.com --new-reg http://localhost:4300/acme/new-reg \
          --certKey %s/key.pem --cert %s/cert.der
        ''' % (tempdir, tempdir), shell=True)
    if issue.wait() != 0:
        sys.exit(1)
    revoke = subprocess.Popen('''
        node revoke.js %s/cert.der %s/key.pem http://localhost:4300/acme/revoke-cert/
        ''' % (tempdir, tempdir), shell=True)
    if revoke.wait() != 0:
        sys.exit(1)

try:
    run_test()
finally:
    status = 0
    # Check whether boulder died. This can happen, for instance, if there was an
    # existing boulder already listening on the port.
    if boulder.poll() is not None:
        print("Boulder died")
        status = 1
    else:
        boulder.kill()

    if cfssl.poll() is not None:
        print("CFSSL died")
        status = 1
    else:
        cfssl.kill()

    shutil.rmtree(tempdir)

    if status == 0:
        print("SUCCESS")
    else:
        print("FAILURE")
    sys.exit(status)

{'fraction_non_alphanumeric': 0.14833295531866636, 'fraction_numerical': 0.014062145611249716, 'mean_word_length': 2.374139250191278, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7626258', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1537, 'n_words': 367}