-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathzboxcli_blobber_availability_test.go
110 lines (95 loc) · 3.84 KB
/
zboxcli_blobber_availability_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package cli_tests
import (
"strconv"
"strings"
"testing"
"time"
cliutil "github.com/0chain/system_test/internal/cli/util"
"github.com/0chain/system_test/internal/cli/model"
"github.com/stretchr/testify/require"
"github.com/0chain/system_test/internal/api/util/test"
)
func TestBlobberAvailability(testSetup *testing.T) {
t := test.NewSystemTest(testSetup)
t.SetSmokeTests("blobber is available switch controls blobber use for allocations")
t.RunSequentially("blobber is available switch controls blobber use for allocations", func(t *test.SystemTest) {
createWallet(t)
startBlobbers := getBlobbers(t)
var blobberToDeactivate *model.BlobberDetails
var activeBlobbers int
for i := range startBlobbers {
if !startBlobbers[i].NotAvailable && !startBlobbers[i].IsKilled && !startBlobbers[i].IsShutdown {
activeBlobbers++
if blobberToDeactivate == nil {
blobberToDeactivate = &startBlobbers[i]
}
}
}
require.NotEqual(t, blobberToDeactivate, "", "no active blobbers")
require.True(t, activeBlobbers > 2, "need at least three active blobbers")
dataShards := 1
parityShards := activeBlobbers - dataShards
output, err := createNewAllocation(t, configPath, createParams(map[string]interface{}{
"data": strconv.Itoa(dataShards),
"parity": strconv.Itoa(parityShards),
"lock": "3.0",
"size": "10000",
}))
require.NoError(t, err, strings.Join(output, "\n"))
beforeAllocationId, err := getAllocationID(output[0])
require.NoError(t, err, "error getting allocation id")
beforeAllocation := getAllocation(t, beforeAllocationId)
setNotAvailability(t, blobberToDeactivate.ID, true)
t.Cleanup(func() { setNotAvailability(t, blobberToDeactivate.ID, false) })
cliutil.Wait(t, 1*time.Second)
betweenBlobbers := getBlobbers(t)
for i := range betweenBlobbers {
if betweenBlobbers[i].ID == blobberToDeactivate.ID {
require.Falsef(t, !betweenBlobbers[i].NotAvailable, "blobber %s should be deactivated", blobberToDeactivate.ID)
}
}
output, err = createNewAllocation(t, configPath, createParams(map[string]interface{}{
"data": strconv.Itoa(dataShards),
"parity": strconv.Itoa(parityShards),
"lock": "3.0",
"size": "10000",
}))
require.Error(t, err, "create allocation should fail")
require.Len(t, output, 1)
require.True(t, strings.Contains(output[0], "not enough blobbers to honor the allocation"))
output, err = updateAllocation(t, configPath, createParams(map[string]interface{}{
"allocation": beforeAllocationId,
"extend": true,
}), true)
require.Nil(t, err, "error updating allocation", strings.Join(output, "\n"))
afterAlloc := getAllocation(t, beforeAllocationId)
require.Greater(t, afterAlloc.ExpirationDate, beforeAllocation.ExpirationDate)
createAllocationTestTeardown(t, beforeAllocationId)
setNotAvailability(t, blobberToDeactivate.ID, false)
cliutil.Wait(t, 1*time.Second)
afterBlobbers := getBlobbers(t)
for i := range betweenBlobbers {
if afterBlobbers[i].ID == blobberToDeactivate.ID {
require.Truef(t, !afterBlobbers[i].NotAvailable, "blobber %s should be activated", blobberToDeactivate.ID)
}
}
output, err = createNewAllocation(t, configPath, createParams(map[string]interface{}{
"data": strconv.Itoa(dataShards),
"parity": strconv.Itoa(parityShards),
"lock": "3.0",
"size": "10000",
}))
require.NoError(t, err, strings.Join(output, "\n"))
afterAllocationId, err := getAllocationID(output[0])
require.NoError(t, err, "error getting allocation id")
createAllocationTestTeardown(t, afterAllocationId)
})
}
func setNotAvailability(t *test.SystemTest, blobberId string, availability bool) {
output, err := updateBlobberInfo(t, configPath, createParams(map[string]interface{}{
"blobber_id": blobberId,
"not_available": availability,
}))
require.NoError(t, err, strings.Join(output, "\n"))
require.Len(t, output, 1)
}