Skip to content

Conversation

@etnbrd
Copy link
Contributor

@etnbrd etnbrd commented Mar 28, 2025

What and why?

This PR implements the synthetics build-and-test command.
Provided with a buildCommand, and an optional buildPluginPort (defaults to 4000) options, this command runs the build command, wait for a successful build, and a dev server spawned by the Datadog build-plugin, to run Synthetics tests against this dev server using the tunnel.

Except the unit tests, this command hasn't been tested properly yet. It'll be done later.

How?

The build-and-test command spawns the build command, and regularly request the expected dev server (e.g. https://localhost:4000) until the build is advertised as successful. Then it runs the tests.

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)

@etnbrd etnbrd added the synthetics Related to [synthetics] label Mar 28, 2025
@etnbrd etnbrd requested review from a team as code owners March 28, 2025 07:58
Copy link
Member

@yoannmoinet yoannmoinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments.

Comment on lines 16 to 29
const port = 4000
const requests: string[] = []
const server = http
.createServer((req, res) => {
requests.push(String(req.url))
res.writeHead(200, {'Content-Type': 'application/json'})
res.end(
JSON.stringify({
status: 'success',
publicPrefix: 'prefix/',
})
)
})
.listen(port)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Instead of creating a server (which bring some complexity to the test), you could mock the axios.get call, or use something like nock.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you concerned with the complexity reading the test implementation, or executing the test?
I understand it's bringing a bit of complexity in both, but given it allows to remain close to the expected implementation, and the test implementation remains quite straightforward, I thought it'd be acceptable.

Copy link
Member

@yoannmoinet yoannmoinet Mar 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was mostly about the complexity of the implementation, and the overhead added to its execution.

For instance, it's quite difficult to create more test cases if needed, like different responses, without having to implement a full fledge server, with features and all. Increasing further the complexity and the overhead.

In the end, it doesn't really add any value to the test, it's used as a tool to assess that the command is fetching, and behave as expected given the server's responses (which is currently only tested with a single response).

Tool that could be replaced by a simpler one, like a mock or nock, which would give us more opportunities to easily test more situations, without adding complexity nor overhead.

Somehow also related to the previous comment about spawn.
Won't block for this though, it was mostly just a nit 👍 for testing perfs and DX.

Copy link
Contributor

@Drarig29 Drarig29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LTGM, left some comments

@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Mar 28, 2025

Datadog Report

Branch report: etnbrd/SYNTH-18574/build-and-test
Commit report: b2103bf
Test service: datadog-ci-tests

✅ 0 Failed, 1329 Passed, 0 Skipped, 1m 48.26s Total duration (30.37s time saved)

@etnbrd etnbrd requested review from Drarig29 and yoannmoinet March 28, 2025 16:13
Copy link
Contributor

@Drarig29 Drarig29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one nit

Copy link
Member

@yoannmoinet yoannmoinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me.

I still have some reservations on the tests not mocking the side systems (shell and server) in order to better focus on the actual command's implementation and responses to specific use cases.

But like I said in my previous comments, I won't block for that.

@etnbrd etnbrd merged commit b0df7cc into master Mar 31, 2025
16 checks passed
@etnbrd etnbrd deleted the etnbrd/SYNTH-18574/build-and-test branch March 31, 2025 12:05
@piloulacdog piloulacdog mentioned this pull request Apr 3, 2025
@Drarig29 Drarig29 mentioned this pull request Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

synthetics Related to [synthetics]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants