From 3d28f0f7a9b223cf4191bf39d698432aa85ce4ef Mon Sep 17 00:00:00 2001 From: Justin Hiemstra Date: Tue, 1 Oct 2024 03:23:31 +0000 Subject: [PATCH] Prevent Director sort tests from leaking between each other --- director/sort_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/director/sort_test.go b/director/sort_test.go index 6d3b22b9f..3645a47c0 100644 --- a/director/sort_test.go +++ b/director/sort_test.go @@ -45,6 +45,10 @@ var yamlMockup string func TestCheckOverrides(t *testing.T) { viper.Reset() + t.Cleanup(func() { + viper.Reset() + geoIPOverrides = nil + }) // We'll also check that our logging feature responsibly reports // what Pelican is telling the user. @@ -138,8 +142,6 @@ func TestCheckOverrides(t *testing.T) { require.Equal(t, expectedCoordinate.Lat, coordinate.Lat) require.Equal(t, expectedCoordinate.Long, coordinate.Long) }) - - viper.Reset() } func TestSortServerAdsByTopo(t *testing.T) { @@ -192,6 +194,7 @@ func TestSortServerAds(t *testing.T) { viper.Reset() t.Cleanup(func() { viper.Reset() + geoIPOverrides = nil }) // A random IP that should geo-resolve to roughly the same location as the Madison server @@ -443,6 +446,8 @@ func TestAssignRandBoundedCoord(t *testing.T) { } func TestGetClientLatLong(t *testing.T) { + // The cache may be populated from previous tests. Wipe it out and start fresh. + clientIpCache.DeleteAll() t.Run("invalid-ip", func(t *testing.T) { // Capture the log and check that the correct error is logged logOutput := &(bytes.Buffer{})