Skip to content

Commit d20544f

Browse files
committed
docs update
1 parent 68ecbb1 commit d20544f

File tree

12 files changed

+148
-26
lines changed

12 files changed

+148
-26
lines changed

book/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
- [Configuration](./framework/configuration.md)
1616
- [Test Configuration](./framework/test_configuration_overrides.md)
1717
- [Components Persistence](framework/components/state.md)
18+
- [Components Cleanup](framework/components/cleanup.md)
1819
- [Components Caching](framework/components/caching.md)
1920
- [External Environment](framework/components/external.md)
2021
- [Secrets]()
21-
- [Docker](framework/docker.md)
2222
- [Observability Stack](framework/observability/observability_stack.md)
2323
- [Metrics](framework/observability/metrics.md)
2424
- [Logs](framework/observability/logs.md)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Components Cleanup
2+
3+
Managing state is challenging, especially in end-to-end testing, we use [ryuk](https://golang.testcontainers.org/features/garbage_collector/#ryuk) and following simple rules:
4+
- If `TESTCONTAINERS_RYUK_DISABLED=true`, no cleanup occurs — containers, volumes, and networks remain on your machine.
5+
6+
Feel free to use `ctf d rm` to remove containers when you are ready.
7+
- If `TESTCONTAINERS_RYUK_DISABLED` is unset, the test environment will be automatically cleaned up a few seconds after the test completes.
8+
9+
10+
Keep in mind that all components are mapped to [static ports](state.md), so without cleanup, only one environment can run at a time.
11+
12+
This design choice simplifies debugging.
13+
14+
A simplified command is available to prune unused volumes, containers, and build caches. Use it when you’re running low on space on your machine.
15+
```
16+
ctf d c
17+
```
18+
19+
<div class="warning">
20+
21+
The framework manages cleanup for both on-chain and off-chain Docker components. However, if your test involves actions like configuring Chainlink jobs, it's best practice to make these actions idempotent, so they can be applied reliably in any environment.
22+
23+
</div>

book/src/framework/docker.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

book/src/framework/first_test.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Run the test
4646
CTF_CONFIGS=smoke.toml go test -v -run TestMe
4747
```
4848

49-
Remove containers
49+
Remove containers (read more about cleanup [here](components/cleanup.md))
5050
```
5151
ctf d rm
5252
```

book/src/framework/getting_started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Allow it to run in `System Settings -> Security Settings` (OS X)
3737
![img.png](images/img.png)
3838

3939

40-
Create an `.envrc` file and do `source .envrc`
40+
Create an `.envrc` file and do `source .envrc` (we recommend to use [direnv](https://direnv.net/), so you don't need to load it every time)
4141
```
4242
export TESTCONTAINERS_RYUK_DISABLED=true # do not remove containers while we develop locally
4343
```

book/src/overview.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
# Intro
22

3-
The Chainlink Testing Framework (CTF) is a blockchain development framework written in Go.
43

5-
Its primary purpose is to help Chainlink developers create extensive integration, e2e, performance, and chaos tests to ensure the stability of the Chainlink project.
64

7-
It can also be helpful to those who just want to use Chainlink oracles in their projects to help test their contracts, or even for those that aren't using Chainlink.
5+
The Chainlink Testing Framework is a toolset designed for end-to-end testing of Chainlink products, focusing on functionality, resiliency, and performance.
86

9-
This documentation is primarily for:
10-
- Engineers looking to write end-to-end tests
11-
- Non-technical users or external developers who want to [setup](framework/interactive.md) `Chainlink` nodes locally
7+
This documentation is intended for:
8+
- Chainlink engineers writing end-to-end tests in [Golang](https://go.dev/)
9+
- Engineers using other languages who want to integrate with the Chainlink platform
1210

1311
To get started with writing tests, refer to the [Framework](./framework/getting_started.md) chapter, where we guide you from basic to more complex scenarios.
1412

13+
If you want to build integration with Chainlink not in [Golang](https://go.dev/), please refer to our [Interactive](framework/interactive.md) chapter.
14+
1515
[Repository](https://github.com/smartcontractkit/chainlink-testing-framework) contains two major pieces:
1616
- [Framework](framework/overview.md)
1717
- [Libraries](libraries.md)
18-
19-
If you're a non-technical user or want to build integration with Chainlink not in `Golang`, please refer to our [Interactive](framework/interactive.md) chapter.

framework/cmd/docker.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,30 @@ import (
99
"strings"
1010
)
1111

12-
func cleanDockerResources() error {
12+
func rmTestContainers() error {
1313
framework.L.Info().Str("label", "framework=ctf").Msg("Cleaning up docker containers")
1414
// Bash command for removing Docker containers and networks with "framework=ctf" label
1515
cmd := exec.Command("bash", "-c", `
1616
docker ps -aq --filter "label=framework=ctf" | xargs -r docker rm -f && \
1717
docker network ls --filter "label=framework=ctf" -q | xargs -r docker network rm && \
18-
docker volume rm postgresql_data
18+
docker volume rm postgresql_data || true
19+
`)
20+
framework.L.Debug().Msg("Running command")
21+
if framework.L.GetLevel() == zerolog.DebugLevel {
22+
fmt.Println(cmd.String())
23+
}
24+
output, err := cmd.CombinedOutput()
25+
if err != nil {
26+
return fmt.Errorf("error running clean command: %s", string(output))
27+
}
28+
return nil
29+
}
30+
31+
func cleanUpDockerResources() error {
32+
framework.L.Info().Msg("Cleaning up docker resources")
33+
// Bash command for removing Docker containers and networks with "framework=ctf" label
34+
cmd := exec.Command("bash", "-c", `
35+
docker system prune -a --volumes -f
1936
`)
2037
framework.L.Debug().Msg("Running command")
2138
if framework.L.GetLevel() == zerolog.DebugLevel {

framework/cmd/interactive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func createComponentsFromForm(form *nodeSetForm) error {
9393
func cleanup(form *nodeSetForm) error {
9494
var err error
9595
f := func() {
96-
err = cleanDockerResources()
96+
err = rmTestContainers()
9797
}
9898
err = spinner.New().
9999
Title("Removing docker resources..").

framework/cmd/main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,24 @@ func main() {
6363
Aliases: []string{"d"},
6464
Usage: "Control docker containers marked with 'framework=ctf' label",
6565
Subcommands: []*cli.Command{
66+
{
67+
Name: "clean",
68+
Aliases: []string{"c"},
69+
Usage: "Cleanup all docker resources: volumes, images, build caches",
70+
Action: func(c *cli.Context) error {
71+
err := cleanUpDockerResources()
72+
if err != nil {
73+
return fmt.Errorf("failed to clean Docker resources: %w", err)
74+
}
75+
return nil
76+
},
77+
},
6678
{
6779
Name: "remove",
6880
Aliases: []string{"rm"},
6981
Usage: "Remove Docker containers and networks with 'framework=ctf' label",
7082
Action: func(c *cli.Context) error {
71-
err := cleanDockerResources()
83+
err := rmTestContainers()
7284
if err != nil {
7385
return fmt.Errorf("failed to clean Docker resources: %w", err)
7486
}

framework/examples/myproject/chaos_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ func TestChaos(t *testing.T) {
5353
verifyServices(t, c)
5454

5555
// Stress container CPU (TODO: it is not portable, works only in CI or Linux VM, cgroups are required)
56-
_, err = chaos.ExecPumba(`stress --stress-image=alexeiled/stress-ng:latest-ubuntu --duration=30s --stressors="--cpu 1 --vm 2 --vm-bytes 1G" node0`, 30*time.Second)
57-
require.NoError(t, err)
58-
verifyServices(t, c)
56+
//_, err = chaos.ExecPumba(`stress --stress-image=alexeiled/stress-ng:latest-ubuntu --duration=30s --stressors="--cpu 1 --vm 2 --vm-bytes 1G" node0`, 30*time.Second)
57+
//require.NoError(t, err)
58+
//verifyServices(t, c)
5959
})
6060
}

0 commit comments

Comments
 (0)