From 426c83b9f6d9a1300552e693e9eb34f0c1037122 Mon Sep 17 00:00:00 2001 From: tomas f <46322567+TomFern@users.noreply.github.com> Date: Tue, 28 May 2024 15:40:41 -0300 Subject: [PATCH 1/6] Add Flaky Test --- main_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main_test.go b/main_test.go index a2adcef..b6a64ab 100644 --- a/main_test.go +++ b/main_test.go @@ -6,6 +6,8 @@ import ( "net/http" "net/http/httptest" "testing" + "math/rand" + "time" ) func createTable() { @@ -145,3 +147,11 @@ func Test_record(t *testing.T) { } dropTable() } + +func TestAPI(t *testing.T) { + rand.Seed(time.Now().UnixNano()) + IsFlaky := rand.Intn(2) == 0 + if !IsFlaky() { + t.Error("Test failed, this is a flaky test!") + } +} \ No newline at end of file From 12bf83adfc1998ffe7ef3fb646009c4b7eeedbd4 Mon Sep 17 00:00:00 2001 From: tomas f <46322567+TomFern@users.noreply.github.com> Date: Tue, 28 May 2024 15:43:38 -0300 Subject: [PATCH 2/6] Fix tests --- main_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index b6a64ab..05368b3 100644 --- a/main_test.go +++ b/main_test.go @@ -151,7 +151,7 @@ func Test_record(t *testing.T) { func TestAPI(t *testing.T) { rand.Seed(time.Now().UnixNano()) IsFlaky := rand.Intn(2) == 0 - if !IsFlaky() { + if !IsFlaky { t.Error("Test failed, this is a flaky test!") } } \ No newline at end of file From e2470fa6f568cb4e0490c62013e7154dca35ddde Mon Sep 17 00:00:00 2001 From: tomas f <46322567+TomFern@users.noreply.github.com> Date: Tue, 28 May 2024 15:45:23 -0300 Subject: [PATCH 3/6] Add API Test --- main_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index 05368b3..f65e0d2 100644 --- a/main_test.go +++ b/main_test.go @@ -152,6 +152,6 @@ func TestAPI(t *testing.T) { rand.Seed(time.Now().UnixNano()) IsFlaky := rand.Intn(2) == 0 if !IsFlaky { - t.Error("Test failed, this is a flaky test!") + t.Error("API Test failed. Reason: timeout") } } \ No newline at end of file From 1fd076f2e55e7ee6dec98f43c2ba17ed4fd782a5 Mon Sep 17 00:00:00 2001 From: tomas f <46322567+TomFern@users.noreply.github.com> Date: Tue, 28 May 2024 20:48:38 -0300 Subject: [PATCH 4/6] add featureA --- main_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main_test.go b/main_test.go index f65e0d2..09fc263 100644 --- a/main_test.go +++ b/main_test.go @@ -154,4 +154,12 @@ func TestAPI(t *testing.T) { if !IsFlaky { t.Error("API Test failed. Reason: timeout") } +} + +func TestFeatureA(t *testing.T) { + rand.Seed(time.Now().UnixNano()) + IsFlaky := rand.Intn(2) == 0 + if !IsFlaky { + t.Error("FeatureA failed. Reason: resource not ready") + } } \ No newline at end of file From e591e4e2c8a8baf124c8599d0420e96823bba5df Mon Sep 17 00:00:00 2001 From: tomas f <46322567+TomFern@users.noreply.github.com> Date: Wed, 29 May 2024 08:45:44 -0300 Subject: [PATCH 5/6] Add FeatureB --- main_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main_test.go b/main_test.go index 09fc263..a02eee8 100644 --- a/main_test.go +++ b/main_test.go @@ -162,4 +162,12 @@ func TestFeatureA(t *testing.T) { if !IsFlaky { t.Error("FeatureA failed. Reason: resource not ready") } +} + +func TestFeatureB(t *testing.T) { + rand.Seed(time.Now().UnixNano()) + IsFlaky := rand.Intn(2) == 0 + if !IsFlaky { + t.Error("FeatureB failed. Reason: connection failed") + } } \ No newline at end of file From 0ace0350ac51488abfa4197c43246977e8217f1d Mon Sep 17 00:00:00 2001 From: TomFern Date: Wed, 29 May 2024 14:26:27 +0000 Subject: [PATCH 6/6] Update Semaphore configuration --- .semaphore/semaphore.yml | 83 ++++++++++++---------------------------- 1 file changed, 25 insertions(+), 58 deletions(-) diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml index 37631d5..9cc2e36 100644 --- a/.semaphore/semaphore.yml +++ b/.semaphore/semaphore.yml @@ -1,85 +1,52 @@ -# Use the latest stable version of Semaphore 2.0 YML syntax: version: v1.0 - -# Name your pipeline. In case you connect multiple pipelines with promotions, -# the name will help you differentiate between, for example, a CI build phase -# and delivery phases. name: Semaphore Go CI example - -# An agent defines the environment in which your code runs. -# It is a combination of one of available machine types and operating -# system images. -# See https://docs.semaphoreci.com/article/20-machine-types -# and https://docs.semaphoreci.com/article/32-ubuntu-1804-image agent: machine: type: e1-standard-2 os_image: ubuntu2004 - -# Blocks are the heart of a pipeline and are executed sequentially. -# Each block has a task that defines one or more jobs. Jobs define the -# commands to execute. -# See https://docs.semaphoreci.com/article/62-concepts blocks: - name: Build project task: jobs: - - name: go get & build - commands: - # Download code from Git repository. This step is mandatory if the - # job is to work with your code. - - checkout - - # Set version of Go: - - sem-version go 1.19 - - go get - - go build -o ./bin/main - - # Store the binary in cache to reuse in further blocks. - # More about caching: https://docs.semaphoreci.com/article/54-toolbox-reference#cache - - cache store $(checksum main.go) bin - + - name: go get & build + commands: + - checkout + - sem-version go 1.19 + - go get + - go build -o ./bin/main + - cache store $(checksum main.go) bin + secrets: + - name: test-home - name: Check code style task: jobs: - - name: gofmt - commands: - # Each job on Semaphore starts from a clean environment, so we - # repeat the required project setup. - - checkout - - sem-version go 1.19 - - gofmt main.go | diff --ignore-tab-expansion main.go - - + - name: gofmt + commands: + - checkout + - sem-version go 1.19 + - gofmt main.go | diff --ignore-tab-expansion main.go - - name: Run tests task: - # This block runs two jobs in parallel and they both share common - # setup steps. We can group them in a prologue. - # See https://docs.semaphoreci.com/article/50-pipeline-yaml#prologue prologue: commands: - checkout - sem-version go 1.19 jobs: - - name: go test - commands: - # Start Postgres database service. - # See https://docs.semaphoreci.com/ci-cd-environment/sem-service-managing-databases-and-services-on-linux/ - - sem-service start postgres - - psql -p 5432 -h localhost -U postgres -c "CREATE DATABASE s2" - - go install gotest.tools/gotestsum@latest - - gotestsum --junitfile junit.xml ./... - - - name: Test web server - commands: - # Restore compiled binary which we created in the first block: - - cache restore $(checksum main.go) - - ./bin/main 8001 & - - curl --silent localhost:8001/time | grep "The current time is" + - name: go test + commands: + - sem-service start postgres + - psql -p 5432 -h localhost -U postgres -c "CREATE DATABASE s2" + - go install gotest.tools/gotestsum@latest + - gotestsum --junitfile junit.xml ./... + - name: Test web server + commands: + - cache restore $(checksum main.go) + - ./bin/main 8001 & + - 'curl --silent localhost:8001/time | grep "The current time is"' epilogue: always: commands: - test-results publish junit.xml - after_pipeline: task: jobs: