From 60463871dbc2e2aa837784b778884365dca1f45a Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 3 Oct 2023 16:49:57 +0300 Subject: [PATCH] [#171] pool: Add test for healthy status monitor Signed-off-by: Alex Vanin --- pool/pool_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pool/pool_test.go b/pool/pool_test.go index bd1c1eb..e953aba 100644 --- a/pool/pool_test.go +++ b/pool/pool_test.go @@ -523,6 +523,44 @@ func TestStatusMonitor(t *testing.T) { require.Equal(t, uint64(count), monitor.overallErrorRate()) require.Equal(t, uint32(1), monitor.currentErrorRate()) + + t.Run("healthy status", func(t *testing.T) { + cases := []struct { + action func(*clientStatusMonitor) + status uint32 + isDialed bool + isHealthy bool + description string + }{ + { + action: func(m *clientStatusMonitor) { m.setUnhealthyOnDial() }, + status: statusUnhealthyOnDial, + isDialed: false, + isHealthy: false, + description: "set unhealthy on dial", + }, + { + action: func(m *clientStatusMonitor) { m.setUnhealthy() }, + status: statusUnhealthyOnRequest, + isDialed: true, + isHealthy: false, + description: "set unhealthy on request", + }, + { + action: func(m *clientStatusMonitor) { m.setHealthy() }, + status: statusHealthy, + isDialed: true, + isHealthy: true, + description: "set healthy", + }, + } + for _, tc := range cases { + tc.action(&monitor) + require.Equal(t, tc.status, monitor.healthy.Load()) + require.Equal(t, tc.isDialed, monitor.isDialed()) + require.Equal(t, tc.isHealthy, monitor.isHealthy()) + } + }) } func TestHandleError(t *testing.T) { -- 2.45.2