From b6bd184f2cfb88d382c374335996a8d22ecb225f Mon Sep 17 00:00:00 2001 From: Marek Aufart Date: Tue, 14 Nov 2023 09:53:01 +0100 Subject: [PATCH] :seedling: Stabilize API tests (#554) Addressing few issues in Hub API tests execution that cause rare/random failures. - Force serial API test execution (-p=1,weird: looked like time.Sleep e.g. in importcsv test, continue with other tests while the sleep). - Run API tests 2x in github action (failure in 1st run means a bug, failure only in 2nd run means likely leftover test data). Together with forcing serial test execution, this should help with test failures debugging. - Updated data cleanup in Review test. --------- Signed-off-by: Marek Aufart --- .github/workflows/main.yml | 1 + .github/workflows/test-nightly.yml | 1 + Makefile | 2 +- test/api/review/api_test.go | 12 ++++++------ 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f23cd7498..212f4d8c1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -58,6 +58,7 @@ jobs: DISCONNECTED=1 make run & sleep 15 # probably a dirty solution HUB_BASE_URL=http://localhost:8080 make test-api + HUB_BASE_URL=http://localhost:8080 make test-api # Intentionaly run 2x to catch data left in Hub DB. test-e2e: runs-on: ubuntu-latest diff --git a/.github/workflows/test-nightly.yml b/.github/workflows/test-nightly.yml index 2cb3116fc..60e81cf83 100644 --- a/.github/workflows/test-nightly.yml +++ b/.github/workflows/test-nightly.yml @@ -26,3 +26,4 @@ jobs: DISCONNECTED=1 make run & sleep 15 # probably a dirty solution HUB_BASE_URL=http://localhost:8080 make test-api + HUB_BASE_URL=http://localhost:8080 make test-api # Intentionaly run 2x to catch data left in Hub DB. diff --git a/Makefile b/Makefile index b957e2272..6d7b410ff 100644 --- a/Makefile +++ b/Makefile @@ -135,7 +135,7 @@ test: # Run Hub REST API tests. test-api: - HUB_BASE_URL=${HUB_BASE_URL} go test -count=1 -v ./test/api/... + HUB_BASE_URL=${HUB_BASE_URL} go test -count=1 -p=1 -v ./test/api/... # Run Hub test suite. test-all: test-unit test-api diff --git a/test/api/review/api_test.go b/test/api/review/api_test.go index 2fd67cf99..013f84842 100644 --- a/test/api/review/api_test.go +++ b/test/api/review/api_test.go @@ -46,11 +46,12 @@ func TestReviewCRUD(t *testing.T) { // Check if the unchanged values remain same or not. AssertEqualReviews(t, got, r) - // Delete Related Applications. - assert.Must(t, Application.Delete(app.ID)) // Delete Review. assert.Must(t, Review.Delete(r.ID)) + // Delete Related Applications. + assert.Must(t, Application.Delete(app.ID)) + // Check if the review is present even after deletion or not. _, err = Review.Get(r.ID) if err == nil { @@ -76,9 +77,6 @@ func TestReviewCRUD(t *testing.T) { destApp := api.Application{ Name: "New Application", Description: "Application for Review", - Review: &api.Ref{ - ID: r.ID, - }, } assert.Must(t, Application.Create(&destApp)) @@ -87,7 +85,8 @@ func TestReviewCRUD(t *testing.T) { t.Errorf(err.Error()) } - gotReview, err := Review.Get(destApp.Review.ID) + destAppRef, _ := Application.Get(destApp.ID) + gotReview, err := Review.Get(destAppRef.Review.ID) if err != nil { fmt.Println(err.Error()) t.Errorf(err.Error()) @@ -98,6 +97,7 @@ func TestReviewCRUD(t *testing.T) { // Delete Review. assert.Must(t, Review.Delete(r.ID)) + assert.Must(t, Review.Delete(gotReview.ID)) // Delete Applications. assert.Must(t, Application.Delete(srcApp.ID))