diff --git a/integration-tests/application_tests/application_test.go b/integration-tests/application_tests/application_test.go index 020dd62fa6a10e8f95b72691d0d2371a2b6710e3..9a1c62a06fed3f5fbef3311eae9edfd36adc75e3 100644 --- a/integration-tests/application_tests/application_test.go +++ b/integration-tests/application_tests/application_test.go @@ -99,6 +99,8 @@ func TestMain(m *testing.M) { if os.Getenv("RABBITMQ") == "" { _ = <-application.eventChannel _ = <-application.eventChannel + } else { + integration_test_utils.ClearRabbitMQQueues() } m.Run() diff --git a/integration-tests/integrationTestUtils/integrationTestUtils.go b/integration-tests/integrationTestUtils/integrationTestUtils.go index daf272f74c1cd1d30c9dd68bc76f2bf8a8f5cbef..7ac5ccf3b13a564180a7e8667e72fadbc34dc439 100644 --- a/integration-tests/integrationTestUtils/integrationTestUtils.go +++ b/integration-tests/integrationTestUtils/integrationTestUtils.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "os/exec" "time" configMgmtPb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/configurationmanagement" @@ -192,3 +193,38 @@ func cleanRolesExceptAdmin(resp *apb.GetRolesResponse, roleService apb.RoleServi return nil } + +func ClearRabbitMQQueues() { + rabbitMQAddress := "localhost" + envVarRabbitmq := os.Getenv("RABBITMQ") + if envVarRabbitmq != "" { + rabbitMQAddress = envVarRabbitmq + } + + // add more queue names if necessary + queues := []string{ + "user", + "role", + "managedNetworkElement", + } + + for _, queue := range queues { + args := []string{ + "-i", + "-u", "guest:guest", + "-H", "\"content-type:application/json\"", + "-X", "POST", + "http://" + rabbitMQAddress + ":15672/api/queues/%2f/" + queue + "/get", + "-d", "{\"count\":10,\"encoding\":\"auto\",\"truncate\":50000,\"ackmode\":\"ack_requeue_false\"}", + } + + cmd := exec.Command("curl", args...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + err := cmd.Run() + if err != nil { + logrus.Info(err) + } + } +}