-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathclient_fileops_limits_test.go
152 lines (121 loc) · 5.18 KB
/
client_fileops_limits_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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package tokenomics_tests
import (
"encoding/json"
"path/filepath"
"strings"
"testing"
"time"
"github.com/0chain/system_test/internal/api/util/test"
climodel "github.com/0chain/system_test/internal/cli/model"
"github.com/0chain/system_test/tests/tokenomics_tests/utils"
"github.com/stretchr/testify/require"
)
func TestClientThrottling(testSetup *testing.T) {
t := test.NewSystemTest(testSetup)
output, err := utils.CreateWallet(t, configPath)
require.Nil(t, err, "Error registering wallet", strings.Join(output, "\n"))
var blobberList []climodel.BlobberInfo
var blobberDetailList []climodel.BlobberDetails
output, err = utils.ListBlobbers(t, configPath, "--json")
require.Nil(t, err, "Error listing blobbers", strings.Join(output, "\n"))
require.Len(t, output, 1)
err = json.Unmarshal([]byte(output[0]), &blobberList)
require.Nil(t, err, "Error unmarshalling blobber list", strings.Join(output, "\n"))
require.True(t, len(blobberList) > 0, "No blobbers found in blobber list")
err = json.Unmarshal([]byte(output[0]), &blobberDetailList)
require.Nil(t, err, "Error unmarshalling blobber list", strings.Join(output, "\n"))
require.True(t, len(blobberList) > 0, "No blobbers found in blobber list")
var blobberListString []string
for _, blobber := range blobberList {
blobberListString = append(blobberListString, blobber.Id)
}
var validatorList []climodel.Validator
output, err = utils.ListValidators(t, configPath, "--json")
require.Nil(t, err, "Error listing validators", strings.Join(output, "\n"))
require.Len(t, output, 1)
err = json.Unmarshal([]byte(output[0]), &validatorList)
require.Nil(t, err, "Error unmarshalling validator list", strings.Join(output, "\n"))
require.True(t, len(validatorList) > 0, "No validators found in validator list")
var validatorListString []string
for _, validator := range validatorList {
validatorListString = append(validatorListString, validator.ID)
}
stakeTokensToBlobbersAndValidators(t, blobberListString, validatorListString, configPath, []float64{
1, 1, 1, 1,
}, 1)
t.RunWithTimeout("Exceeding upload limits should blacklist user on blobber", 20*time.Minute, func(t *test.SystemTest) {
_, err = utils.CreateWallet(t, configPath)
require.Nil(t, err, "Error registering wallet", strings.Join(output, "\n"))
// 1. Create an allocation with 1 data shard and 1 parity shard.
allocationId := utils.SetupAllocation(t, configPath, map[string]interface{}{
"size": 10 * MB,
"tokens": 1,
"data": 1,
"parity": 1,
})
for i := 0; i < 2; i++ {
remotepath := "/dir/"
filesize := 64 * KB
filename := utils.GenerateRandomTestFileName(t)
err = utils.CreateFileWithSize(filename, int64(filesize))
require.Nil(t, err)
output, err = utils.UploadFile(t, configPath, map[string]interface{}{
"allocation": allocationId,
"remotepath": remotepath + filepath.Base(filename),
"localpath": filename,
}, false)
require.Nil(t, err, "error uploading file", strings.Join(output, "\n"))
}
time.Sleep(1 * time.Minute) // Wait for blacklist worker to run
remotepath := "/dir/"
filesize := 64 * KB
filename := utils.GenerateRandomTestFileName(t)
err = utils.CreateFileWithSize(filename, int64(filesize))
require.Nil(t, err)
_, err = utils.UploadFile(t, configPath, map[string]interface{}{
"allocation": allocationId,
"remotepath": remotepath + filepath.Base(filename),
"localpath": filename,
}, false)
require.NotNil(t, err, "File upload is expected to fail")
})
t.RunWithTimeout("File upload should fail on exceeding max number of files", 20*time.Minute, func(t *test.SystemTest) {
output, err := utils.CreateWalletForName(t, configPath, "client_wallet_2")
require.Nil(t, err, "Error registering wallet", strings.Join(output, "\n"))
_, err = utils.ExecuteFaucetWithTokens(t, configPath, 9)
require.Nil(t, err, "Error executing faucet", strings.Join(output, "\n"))
output, err = utils.CreateNewAllocation(t, configPath, utils.CreateParams(map[string]interface{}{
"size": 10 * MB,
"data": 1,
"lock": 2,
"parity": 1,
}))
require.Nil(t, err, "Error creating allocation", strings.Join(output, "\n"))
allocationId, err := utils.GetAllocationID(output[0])
require.Nil(t, err, "Error getting allocation ID", strings.Join(output, "\n"))
for i := 0; i < 2; i++ {
remotepath := "/dir/"
filesize := 1024
filename := utils.GenerateRandomTestFileName(t)
err = utils.CreateFileWithSize(filename, int64(filesize))
require.Nil(t, err)
output, err = utils.UploadFile(t, configPath, map[string]interface{}{
"allocation": allocationId,
"remotepath": remotepath + filepath.Base(filename),
"localpath": filename,
}, false)
require.Nil(t, err, "error uploading file", strings.Join(output, "\n"))
}
remotepath := "/dir/"
filesize := 1024
filename := utils.GenerateRandomTestFileName(t)
err = utils.CreateFileWithSize(filename, int64(filesize))
require.Nil(t, err)
_, err = utils.UploadFile(t, configPath, map[string]interface{}{
"allocation": allocationId,
"remotepath": remotepath + filepath.Base(filename),
"localpath": filename,
}, false)
require.NotNil(t, err, "File upload is expected to fail as we already uploaded max files allowed")
})
}