github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/ais/test/health_test.go (about) 1 // Package integration_test. 2 /* 3 * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package integration_test 6 7 import ( 8 "testing" 9 10 "github.com/NVIDIA/aistore/api" 11 "github.com/NVIDIA/aistore/api/apc" 12 "github.com/NVIDIA/aistore/core/meta" 13 "github.com/NVIDIA/aistore/tools" 14 "github.com/NVIDIA/aistore/tools/tassert" 15 ) 16 17 // health should respond with 200 even is node is unregistered 18 func unregisteredNodeHealth(t *testing.T, proxyURL string, si *meta.Snode) { 19 err := api.Health(tools.BaseAPIParams(si.PubNet.URL)) 20 tassert.CheckError(t, err) 21 22 smapOrig := tools.GetClusterMap(t, proxyURL) 23 args := &apc.ActValRmNode{DaemonID: si.ID(), SkipRebalance: true} 24 baseParams := tools.BaseAPIParams(proxyURL) 25 _, err = api.StartMaintenance(baseParams, args) 26 tassert.CheckFatal(t, err) 27 targetCount := smapOrig.CountActiveTs() 28 proxyCount := smapOrig.CountActivePs() 29 if si.IsProxy() { 30 proxyCount-- 31 } else { 32 targetCount-- 33 } 34 _, err = tools.WaitForClusterState(proxyURL, "decommission node", smapOrig.Version, proxyCount, targetCount) 35 tassert.CheckFatal(t, err) 36 defer func() { 37 val := &apc.ActValRmNode{DaemonID: si.ID()} 38 rebID, err := api.StopMaintenance(baseParams, val) 39 tassert.CheckFatal(t, err) 40 _, err = tools.WaitForClusterState(proxyURL, "join node", smapOrig.Version, smapOrig.CountActivePs(), 41 smapOrig.CountActiveTs()) 42 tassert.CheckFatal(t, err) 43 tools.WaitForRebalanceByID(t, baseParams, rebID) 44 }() 45 46 err = api.Health(tools.BaseAPIParams(si.PubNet.URL)) 47 tassert.CheckError(t, err) 48 } 49 50 func TestPrimaryProxyHealth(t *testing.T) { 51 smap := tools.GetClusterMap(t, proxyURL) 52 err := api.Health(tools.BaseAPIParams(smap.Primary.PubNet.URL)) 53 tassert.CheckError(t, err) 54 } 55 56 func TestUnregisteredProxyHealth(t *testing.T) { 57 tools.CheckSkip(t, &tools.SkipTestArgs{RequiredDeployment: tools.ClusterTypeLocal, MinProxies: 2}) 58 59 var ( 60 proxyURL = tools.GetPrimaryURL() 61 smap = tools.GetClusterMap(t, proxyURL) 62 ) 63 64 proxyCnt := smap.CountActivePs() 65 proxy, err := smap.GetRandProxy(true /*excludePrimary*/) 66 tassert.CheckError(t, err) 67 unregisteredNodeHealth(t, proxyURL, proxy) 68 69 smap = tools.GetClusterMap(t, proxyURL) 70 tassert.Fatalf(t, proxyCnt == smap.CountActivePs(), "expected number of proxies to be the same after the test") 71 } 72 73 func TestTargetHealth(t *testing.T) { 74 var ( 75 proxyURL = tools.GetPrimaryURL() 76 smap = tools.GetClusterMap(t, proxyURL) 77 ) 78 tsi, err := smap.GetRandTarget() 79 tassert.CheckFatal(t, err) 80 err = api.Health(tools.BaseAPIParams(tsi.PubNet.URL)) 81 tassert.CheckFatal(t, err) 82 } 83 84 func TestUnregisteredTargetHealth(t *testing.T) { 85 var ( 86 proxyURL = tools.GetPrimaryURL() 87 smap = tools.GetClusterMap(t, proxyURL) 88 ) 89 90 targetsCnt := smap.CountActiveTs() 91 target, err := smap.GetRandTarget() 92 tassert.CheckFatal(t, err) 93 unregisteredNodeHealth(t, proxyURL, target) 94 95 smap = tools.GetClusterMap(t, proxyURL) 96 tassert.Fatalf(t, targetsCnt == smap.CountActiveTs(), "expected number of targets to be the same after the test") 97 }