@@ -18,7 +18,7 @@ test_expect_success 'disconnected: swarm stats requires running daemon' '
18
18
'
19
19
20
20
# swarm limit|stats should fail in online mode by default
21
- # because Resource Manager is opt-in for now
21
+ # because Resource Manager is opt-in
22
22
test_launch_ipfs_daemon
23
23
24
24
test_expect_success ' ResourceMgr disabled by default: swarm limit requires Swarm.ResourceMgr.Enabled' '
@@ -30,20 +30,31 @@ test_expect_success 'ResourceMgr disabled by default: swarm stats requires Swarm
30
30
test_should_contain "missing ResourceMgr" actual
31
31
'
32
32
33
- # swarm limit|stat should work when Swarm.ResourceMgr.Enabled
34
33
test_kill_ipfs_daemon
35
34
36
- test_expect_success " test_config_set succeeds" "
35
+ test_expect_success " setting an invalid limit should result in a failure" "
36
+ test_expect_code 1 ipfs config --json Swarm.ResourceMgr.Limits.System.Conns 'asdf' 2> actual &&
37
+ test_should_contain 'failed to unmarshal' actual
38
+ "
39
+
40
+ # swarm limit|stat should work when Swarm.ResourceMgr.Enabled
41
+ test_expect_success " test enabling resource manager" "
37
42
ipfs config --json Swarm.ResourceMgr.Enabled true &&
38
- ipfs config --json Swarm.ResourceMgr.Limits.System.Conns 99999
43
+ ipfs config --json Swarm.ResourceMgr &&
44
+ jq -e '.Swarm.ResourceMgr.Enabled == true'
39
45
"
40
46
41
47
test_launch_ipfs_daemon
42
48
49
+ test_expect_success " test setting system conns limit" "
50
+ ipfs config --json Swarm.ResourceMgr.Enabled true &&
51
+ ipfs config --json Swarm.ResourceMgr.Limits.System.Conns 99999
52
+ "
53
+
43
54
# every scope has the same fields, so we only inspect System
44
55
test_expect_success ' ResourceMgr enabled: swarm limit' '
45
56
ipfs swarm limit system --enc=json | tee json &&
46
- jq -e " .Conns == 99999" < json &&
57
+ jq -e .Conns < json &&
47
58
jq -e .ConnsInbound < json &&
48
59
jq -e .ConnsOutbound < json &&
49
60
jq -e .FD < json &&
@@ -65,6 +76,20 @@ test_expect_success 'ResourceMgr enabled: swarm stats' '
65
76
jq -e .Transient.Memory < json
66
77
'
67
78
79
+ # shut down the daemon, set a limit in the config, and verify that it's applied
80
+ test_kill_ipfs_daemon
81
+
82
+ test_expect_success " set system conn limit" "
83
+ ipfs config --json Swarm.ResourceMgr.Limits.System.Conns 99999
84
+ "
85
+
86
+ test_launch_ipfs_daemon
87
+
88
+ test_expect_success ' ResourceMgr enabled: swarm limit' '
89
+ ipfs swarm limit system --enc=json | tee json &&
90
+ jq -e ".Conns == 99999" < json
91
+ '
92
+
68
93
test_expect_success ' Set system memory limit while the daemon is running' '
69
94
ipfs swarm limit system | jq ".Memory = 99998" > system.json &&
70
95
ipfs swarm limit system system.json
@@ -78,5 +103,53 @@ test_expect_success 'The new system limits are in the swarm limit output' '
78
103
ipfs swarm limit system --enc=json | jq -e ".Memory == 99998"
79
104
'
80
105
106
+ # now test all the other scopes
107
+ test_expect_success ' Set limit on transient scope' '
108
+ ipfs swarm limit transient | jq ".Memory = 88888" > transient.json &&
109
+ ipfs swarm limit transient transient.json &&
110
+ jq -e ".Swarm.ResourceMgr.Limits.Transient.Memory == 88888" < "$IPFS_PATH/config" &&
111
+ ipfs swarm limit transient --enc=json | tee limits &&
112
+ jq -e ".Memory == 88888" < limits
113
+ '
114
+
115
+ test_expect_success ' Set limit on service scope' '
116
+ ipfs swarm limit svc:foo | jq ".Memory = 77777" > service-foo.json &&
117
+ ipfs swarm limit svc:foo service-foo.json --enc=json &&
118
+ jq -e ".Swarm.ResourceMgr.Limits.Service.foo.Memory == 77777" < "$IPFS_PATH/config" &&
119
+ ipfs swarm limit svc:foo --enc=json | tee limits &&
120
+ jq -e ".Memory == 77777" < limits
121
+ '
122
+
123
+ test_expect_success ' Set limit on protocol scope' '
124
+ ipfs swarm limit proto:foo | jq ".Memory = 66666" > proto-foo.json &&
125
+ ipfs swarm limit proto:foo proto-foo.json --enc=json &&
126
+ jq -e ".Swarm.ResourceMgr.Limits.Protocol.foo.Memory == 66666" < "$IPFS_PATH/config" &&
127
+ ipfs swarm limit proto:foo --enc=json | tee limits &&
128
+ jq -e ".Memory == 66666" < limits
129
+ '
130
+
131
+ # any valid peer id
132
+ PEER_ID=QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN
133
+
134
+ test_expect_success ' Set limit on peer scope' '
135
+ ipfs swarm limit peer:$PEER_ID | jq ".Memory = 66666" > peer-$PEER_ID.json &&
136
+ ipfs swarm limit peer:$PEER_ID peer-$PEER_ID.json --enc=json &&
137
+ jq -e ".Swarm.ResourceMgr.Limits.Peer.${PEER_ID}.Memory == 66666" < "$IPFS_PATH/config" &&
138
+ ipfs swarm limit peer:$PEER_ID --enc=json | tee limits &&
139
+ jq -e ".Memory == 66666" < limits
140
+ '
141
+
142
+ test_expect_success ' Get limit for peer scope with an invalid peer ID' '
143
+ test_expect_code 1 ipfs swarm limit peer:foo 2> actual &&
144
+ test_should_contain "invalid peer ID" actual
145
+ '
146
+
147
+ test_expect_success ' Set limit for peer scope with an invalid peer ID' '
148
+ echo "{\"Memory\": 99}" > invalid-peer-id.json &&
149
+ test_expect_code 1 ipfs swarm limit peer:foo invalid-peer-id.json 2> actual &&
150
+ test_should_contain "invalid peer ID" actual
151
+ '
152
+
81
153
test_kill_ipfs_daemon
154
+
82
155
test_done
0 commit comments