|
| 1 | +#!/usr/bin/env python |
| 2 | +"""Run Integ Tests based on the changed files |
| 3 | +
|
| 4 | +""" |
| 5 | +from subprocess import call, check_call, Popen, PIPE |
| 6 | + |
| 7 | +# Minimal modules to tests when core changes are detected. |
| 8 | +# s3 - xml, dynamodb - json, sqs - query |
| 9 | +core_modules_to_test = ["s3", "dynamodb", "sqs"] |
| 10 | + |
| 11 | +# Minimal modules to tests when http client changes are detected. |
| 12 | +# s3 - streaming/non streaming, kinesis - h2 |
| 13 | +http_modules_to_test = { |
| 14 | + "apache-client": ["s3", "apache-client"], |
| 15 | + "netty-nio-client": ["kinesis", "s3", "netty-nio-client"], |
| 16 | + "url-connection-client": ["url-connection-client"] |
| 17 | +} |
| 18 | + |
| 19 | +def check_diffs(): |
| 20 | + """ |
| 21 | + Retrieve the changed files |
| 22 | + """ |
| 23 | + ret = Popen(["git", "diff", "HEAD^", "--name-only"], stdout=PIPE) |
| 24 | + |
| 25 | + diff, stderr = ret.communicate() |
| 26 | + return diff.splitlines(False) |
| 27 | + |
| 28 | +def get_modules(file_path): |
| 29 | + """ |
| 30 | + Parse the changed file path and get the respective module names |
| 31 | + """ |
| 32 | + path = file_path.split('/') |
| 33 | + top_directory = path[0] |
| 34 | + |
| 35 | + if top_directory in ["core", "codegen"]: |
| 36 | + return core_modules_to_test |
| 37 | + if top_directory in ["http-clients"]: |
| 38 | + return http_modules_to_test[path[1]] |
| 39 | + elif top_directory== "services": |
| 40 | + return path[1] |
| 41 | + |
| 42 | +def run_tests(modules): |
| 43 | + """ |
| 44 | + Run integration tests for the given modules |
| 45 | + """ |
| 46 | + print("Running integ tests in the following modules: " + ', '.join(modules)) |
| 47 | + modules_to_include = "" |
| 48 | + |
| 49 | + for m in modules: |
| 50 | + modules_to_include += ":" + m + "," |
| 51 | + |
| 52 | + # remove last comma |
| 53 | + modules_to_include = modules_to_include[:-1] |
| 54 | + |
| 55 | + # build necessary dependencies first |
| 56 | + check_call(["mvn", "clean", "install", "-pl", modules_to_include, "-P", "quick", "--am", "-Dmaven.wagon.httpconnectionManager.maxPerRoute=2"]) |
| 57 | + check_call(["mvn", "verify", "-pl", modules_to_include, "-P", "integration-tests", "-Dfailsafe.rerunFailingTestsCount=1"]) |
| 58 | + |
| 59 | +if __name__ == "__main__": |
| 60 | + diffs = check_diffs() |
| 61 | + modules = set() |
| 62 | + for d in diffs: |
| 63 | + module = get_modules(d) |
| 64 | + if isinstance(module, list): |
| 65 | + modules.update(module) |
| 66 | + elif module: |
| 67 | + modules.add(module) |
| 68 | + |
| 69 | + if modules: |
| 70 | + run_tests(modules) |
| 71 | + else: |
| 72 | + print("No modules configured to run. Skipping integ tests") |
0 commit comments