github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/ais/test/xaction_test.go (about) 1 // Package integration_test. 2 /* 3 * Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package integration_test 6 7 import ( 8 "testing" 9 "time" 10 11 "github.com/NVIDIA/aistore/api" 12 "github.com/NVIDIA/aistore/api/apc" 13 "github.com/NVIDIA/aistore/cmn/cos" 14 "github.com/NVIDIA/aistore/cmn/mono" 15 "github.com/NVIDIA/aistore/nl" 16 "github.com/NVIDIA/aistore/tools" 17 "github.com/NVIDIA/aistore/tools/tassert" 18 "github.com/NVIDIA/aistore/tools/tlog" 19 "github.com/NVIDIA/aistore/xact" 20 ) 21 22 func TestXactionNotFound(t *testing.T) { 23 var ( 24 proxyURL = tools.RandomProxyURL(t) 25 baseParams = tools.BaseAPIParams(proxyURL) 26 ) 27 _, err := api.QueryXactionSnaps(baseParams, &xact.ArgsMsg{ID: "dummy-" + cos.GenUUID()}) 28 tools.CheckErrIsNotFound(t, err) 29 } 30 31 func TestXactionAllStatus(t *testing.T) { 32 tests := []struct { 33 running bool 34 force bool 35 }{ 36 {running: false, force: false}, 37 {running: true, force: false}, 38 {running: false, force: true}, 39 {running: true, force: true}, 40 } 41 for _, test := range tests { 42 for kind := range xact.Table { 43 xargs := xact.ArgsMsg{Kind: kind, OnlyRunning: test.running, Force: test.force} 44 if mono.NanoTime()&0x1 == 0x1 { 45 _, xname := xact.GetKindName(kind) 46 xargs.Kind = xname 47 } 48 vec, err := api.GetAllXactionStatus(baseParams, &xargs) 49 tassert.CheckFatal(t, err) 50 if len(vec) == 0 { 51 continue 52 } 53 if kind != apc.ActList { 54 tlog.Logln(vec.String()) 55 } 56 for _, ns := range vec { 57 tassert.Errorf(t, ns.Kind == kind, "kind %q vs %q", ns.Kind, kind) 58 } 59 if !test.running { 60 continue 61 } 62 63 // check fin time for all running 64 var aborted nl.StatusVec 65 for _, ns := range vec { 66 if ns.AbortedX { 67 tlog.Logf("%q is aborted but hasn't finished yet\n", ns.String()) 68 aborted = append(aborted, ns) 69 } else { 70 // doesn't appear to be aborted and is, therefore, expected to be running 71 tassert.Errorf(t, ns.EndTimeX == 0, "%q: non-sero fin time=%v", 72 ns.String(), time.Unix(0, ns.EndTimeX)) 73 } 74 } 75 if len(aborted) == 0 { 76 continue 77 } 78 79 // re-check after a while 80 time.Sleep(2 * time.Second) 81 82 xargs = xact.ArgsMsg{Kind: kind, OnlyRunning: false, Force: test.force} 83 vec, err = api.GetAllXactionStatus(baseParams, &xargs) 84 tassert.CheckFatal(t, err) 85 for _, a := range aborted { 86 found := false 87 for _, ns := range vec { 88 if a.UUID == ns.UUID { 89 found = true 90 tassert.Errorf(t, ns.EndTimeX != 0, "%q: was aborted, is expected to be finished", 91 ns.String()) 92 break 93 } 94 } 95 tassert.Errorf(t, found, 96 "%q: was aborted, is missing in the all-xaction-status results", a.String()) 97 } 98 } 99 } 100 }