[HTML payload içeriği buraya]
29.5 C
Jakarta
Sunday, May 17, 2026

Accelerating CI with AWS CodeBuild: Parallel take a look at execution now accessible


Voiced by Polly

I’m excited to announce that AWS CodeBuild now helps parallel take a look at execution, so you possibly can run your take a look at suites concurrently and cut back construct instances considerably.

With the demo mission I wrote for this publish, the full take a look at time went down from 35 minutes to six minutes, together with the time to provision the environments. These two screenshots from the AWS Administration Console present the distinction.

Sequential execution of the take a look at suite

CodeBuild Parallel Test Results

Parallel execution of the take a look at suite

CodeBuild Parallel Test Results

Very lengthy take a look at instances pose a major problem when operating steady integration (CI) at scale. As tasks develop in complexity and staff dimension, the time required to execute complete take a look at suites can improve dramatically, resulting in prolonged pipeline execution instances. This not solely delays the supply of recent options and bug fixes, but in addition hampers developer productiveness by forcing them to attend for construct outcomes earlier than continuing with their duties. I’ve skilled pipelines that took as much as 60 minutes to run, solely to fail on the final step, requiring an entire rerun and additional delays. These prolonged cycles can erode developer belief within the CI course of, contribute to frustration, and in the end decelerate your complete software program supply cycle. Furthermore, long-running assessments can result in useful resource rivalry, elevated prices due to wasted computing energy, and decreased total effectivity of the event course of.

With parallel take a look at execution in CodeBuild, now you can run your assessments concurrently throughout a number of construct compute environments. This characteristic implements a sharding strategy the place every construct node independently executes a subset of your take a look at suite. CodeBuild offers surroundings variables that determine the present node quantity and the full variety of nodes, that are used to find out which assessments every node ought to run. There isn’t a management construct node or coordination between nodes at construct time—every node operates independently to execute its assigned portion of your assessments.

To allow take a look at splitting, configure the batch fanout part in your buildspec.xml, specifying the specified parallelism stage and different related parameters. Moreover, use the codebuild-tests-run utility in your construct step, together with the suitable take a look at instructions and the chosen splitting technique.

The assessments are cut up based mostly on the sharding technique you specify. codebuild-tests-run presents two sharding methods:

  • Equal-distribution. This technique types take a look at recordsdata alphabetically and distributes them in chunks equally throughout parallel take a look at environments. Modifications within the names or amount of take a look at recordsdata would possibly reassign recordsdata throughout shards.
  • Stability. This technique fixes the distribution of assessments throughout shards through the use of a constant hashing algorithm. It maintains current file-to-shard assignments when new recordsdata are added or eliminated.

CodeBuild helps computerized merging of take a look at stories when operating assessments in parallel. With computerized take a look at report merging, CodeBuild consolidates assessments stories right into a single take a look at abstract, simplifying consequence evaluation. The merged report consists of aggregated move/fail statuses, take a look at durations, and failure particulars, lowering the necessity for handbook report processing. You’ll be able to view the merged leads to the CodeBuild console, retrieve them utilizing the AWS Command Line Interface (AWS CLI), or combine them with different reporting instruments to streamline take a look at evaluation.

Let’s have a look at the way it works
Let me show tips on how to implement parallel testing in a mission. For this demo, I created a really primary Python mission with a whole bunch of assessments. To hurry issues up, I requested Amazon Q Developer on the command line to create a mission and 1,800 take a look at circumstances. Every take a look at case is in a separate file and takes one second to finish. Operating all assessments in a sequence requires half-hour, excluding the time to provision the surroundings.

On this demo, I run the take a look at suite on ten compute environments in parallel and measure how lengthy it takes to run the suite.

To take action, I added a buildspec.yml file to my mission.

model: 0.2

batch:
  fast-fail: false
  build-fanout:
    parallelism: 10 # ten runtime environments 
    ignore-failure: false

phases:
  set up:
    instructions:
      - echo 'Putting in Python dependencies'
      - dnf set up -y python3 python3-pip
      - pip3 set up --upgrade pip
      - pip3 set up pytest
  construct:
    instructions:
      - echo 'Operating Python Checks'
      - |
         codebuild-tests-run 
          --test-command 'python -m pytest --junitxml=report/test_report.xml' 
          --files-search "codebuild-glob-search 'assessments/test_*.py'" 
          --sharding-strategy 'equal-distribution'
  post_build:
    instructions:
      - echo "Take a look at execution accomplished"

stories:
  pytest_reports:
    recordsdata:
      - "*.xml"
    base-directory: "report"
    file-format: JUNITXML 

There are three components to spotlight within the YAML file.

First, there’s a build-fanout part beneath batch. The parallelism command tells CodeBuild what number of take a look at environments to run in parallel. The ignore-failure command signifies if failure in any of the fanout construct duties might be ignored.

Second, I exploit the pre-installed codebuild-tests-run command to run my assessments.

This command receives the entire record of take a look at recordsdata and decides which of the assessments should be run on the present node.

  • Use the sharding-strategy argument to decide on between equally distributed or secure distribution, as I defined earlier.
  • Use the files-search argument to move all of the recordsdata which are candidates for a run. We suggest to make use of the supplied codebuild-glob-search command for efficiency causes, however any file search software, comparable to discover(1), will work.
  • I move the precise take a look at command to run on the shard with the test-command argument.

Lastly, the stories part instructs CodeBuild to gather and merge the take a look at stories on every node.

Then, I open the CodeBuild console to create a mission and a batch construct configuration for this mission. There’s nothing new right here, so I’ll spare you the small print. The documentation has all the small print to get you beganParallel testing works on batch builds. Be certain to configure your mission to run in batch.

CodeBuild : create a batch build

Now, I’m able to set off an execution of the take a look at suite. I can commit new code on my GitHub repository or set off the construct within the console.

CodeBuild : trigger a new build

After a couple of minutes, I see a standing report of the completely different steps of the construct; with a standing for every take a look at surroundings or shard.

CodeBuild: status

When the take a look at is full, I choose the Studies tab to entry the merged take a look at stories.

CodeBuild: test reports

The Studies part aggregates all take a look at knowledge from all shards and retains the historical past for all builds. I choose my most up-to-date construct within the Report historical past part to entry the detailed report.

CodeBuild: Test Report

As anticipated, I can see the aggregated and the person standing for every of my 1,800 take a look at circumstances. On this demo, they’re all passing, and the report is inexperienced.

The 1,800 assessments of the demo mission take one second every to finish. After I run this take a look at suite sequentially, it took 35 minutes to finish. After I run the take a look at suite in parallel on ten compute environments, it took 6 minutes to finish, together with the time to provision the environments. The parallel run took 17.9 % of the time of the sequential run. Precise numbers will differ along with your tasks.

Further issues to know
This new functionality is suitable with all testing frameworks. The documentation consists of examples for Django, Elixir, Go, Java (Maven), Javascript (Jest), Kotlin, PHPUnit, Pytest, Ruby (Cucumber), and Ruby (RSpec).

For take a look at frameworks that don’t settle for space-separated lists, the codebuild-tests-run CLI offers a versatile various by way of the CODEBUILD_CURRENT_SHARD_FILES surroundings variable. This variable accommodates a newline-separated record of take a look at file paths for the present construct shard. You should use it to adapt to completely different take a look at framework necessities and format take a look at file names.

You’ll be able to additional customise how assessments are cut up throughout environments by writing your individual sharding script and utilizing the CODEBUILD_BATCH_BUILD_IDENTIFIER surroundings variable, which is mechanically set in every construct. You should use this method to implement framework-specific parallelization or optimization.

Pricing and availability
With parallel take a look at execution, now you can full your take a look at suites in a fraction of the time beforehand required, accelerating your improvement cycle and enhancing your staff’s productiveness.

Parallel take a look at execution is offered on all three compute modes supplied by CodeBuild: on-demand, reserved capability, and AWS Lambda compute.

This functionality is offered right now in all AWS Areas the place CodeBuild is obtainable, with no extra value past the usual CodeBuild pricing for the compute sources used.

I invite you to attempt parallel take a look at execution in CodeBuild right now. Go to the AWS CodeBuild documentation to be taught extra and get began with parallelizing your assessments.

— seb

PS: Right here’s the immediate I used to create the demo software and its take a look at suite: “I’m writing a weblog publish to announce codebuild parallel testing. Write a quite simple python app that has a whole bunch of assessments, every take a look at in a separate take a look at file. Every take a look at takes one second to finish.”


How is the Information Weblog doing? Take this 1 minute survey!

(This survey is hosted by an exterior firm. AWS handles your info as described within the AWS Privateness Discover. AWS will personal the info gathered through this survey and won’t share the knowledge collected with survey respondents.)

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles