@@ -20,6 +20,7 @@ package postgrescluster
2020
2121import (
2222 "context"
23+ "strconv"
2324 "testing"
2425
2526 "github.com/pkg/errors"
@@ -326,10 +327,27 @@ func TestReconcilePGBouncerService(t *testing.T) {
326327 // CRD validation looks only at the new/incoming value of fields. Confirm
327328 // that each ServiceType can change to any other ServiceType. Forbidding
328329 // certain transitions requires a validating webhook.
330+ serviceTypeChangeClusterCounter := 0
329331 for _ , beforeType := range serviceTypes {
330332 for _ , changeType := range serviceTypes {
331333 t .Run (beforeType + "To" + changeType , func (t * testing.T ) {
332- cluster := cluster .DeepCopy ()
334+ // Creating fresh clusters for these tests
335+ clusterNamespace := cluster .Namespace
336+ cluster := testCluster ()
337+ cluster .Namespace = clusterNamespace
338+
339+ // Note (dsessler): Adding a number to each cluster name to make cluster/service
340+ // names unique to work around an intermittent race condition where a service
341+ // from a prior test has not been deleted yet when the next test runs, causing
342+ // the test to fail due to non-matching IP addresses.
343+ cluster .Name += "-" + strconv .Itoa (serviceTypeChangeClusterCounter )
344+ assert .NilError (t , cc .Create (ctx , cluster ))
345+
346+ cluster .Spec .Proxy = & v1beta1.PostgresProxySpec {
347+ PGBouncer : & v1beta1.PGBouncerPodSpec {
348+ Port : initialize .Int32 (19041 ),
349+ },
350+ }
333351 cluster .Spec .Proxy .PGBouncer .Service = & v1beta1.ServiceSpec {Type : beforeType }
334352
335353 before , err := reconciler .reconcilePGBouncerService (ctx , cluster )
@@ -352,6 +370,7 @@ func TestReconcilePGBouncerService(t *testing.T) {
352370 assert .NilError (t , err , "\n %#v" , errors .Unwrap (err ))
353371 assert .Equal (t , after .Spec .ClusterIP , before .Spec .ClusterIP ,
354372 "expected to keep the same ClusterIP" )
373+ serviceTypeChangeClusterCounter ++
355374 })
356375 }
357376 }
0 commit comments