@cryptotaxi247 / kubo / commits / 840eaa759

test: parallelize more of rcmgr Go tests

Gus Eggert committed Mar 8, 2023 at 16:25 UTC 840eaa75990c3efb67e4404c9f0e7d25f091c152
2 files changed +50 -40
test/cli/harness/node.go
-8
@@ -121,14 +121,6 @@ func (n *Node) UpdateUserSuppliedResourceManagerOverrides(f func(overrides *rcmg
121 n.WriteUserSuppliedResourceOverrides(overrides)
122 }
123
124 -func (n *Node) UpdateConfigAndUserSuppliedResourceManagerOverrides(f func(cfg *config.Config, overrides *rcmgr.PartialLimitConfig)) {
125 - overrides := n.ReadUserResourceOverrides()
126 - cfg := n.ReadConfig()
127 - f(cfg, overrides)
128 - n.WriteConfig(cfg)
129 - n.WriteUserSuppliedResourceOverrides(overrides)
130 -}
131 -
124 func (n *Node) IPFS(args ...string) *RunResult {
125 res := n.RunIPFS(args...)
126 n.Runner.AssertNoError(res)
test/cli/rcmgr_test.go
+50 -32
@@ -49,6 +49,7 @@ func TestRcmgr(t *testing.T) {
49 })
50
51 t.Run("Very high connmgr highwater", func(t *testing.T) {
52 + t.Parallel()
53 node := harness.NewT(t).NewNode().Init()
54 node.UpdateConfig(func(cfg *config.Config) {
55 cfg.Swarm.ConnMgr.HighWater = config.NewOptionalInteger(1000)
@@ -74,6 +75,7 @@ func TestRcmgr(t *testing.T) {
75 node.StartDaemon()
76
77 t.Run("conns and streams are above 800 for default connmgr settings", func(t *testing.T) {
78 + t.Parallel()
79 res := node.RunIPFS("swarm", "resources", "--enc=json")
80 require.Equal(t, 0, res.ExitCode())
81 limits := unmarshalLimits(t, res.Stdout.Bytes())
@@ -87,6 +89,7 @@ func TestRcmgr(t *testing.T) {
89 })
90
91 t.Run("limits should succeed", func(t *testing.T) {
92 + t.Parallel()
93 res := node.RunIPFS("swarm", "resources", "--enc=json")
94 assert.Equal(t, 0, res.ExitCode())
95
@@ -106,6 +109,7 @@ func TestRcmgr(t *testing.T) {
109 })
110
111 t.Run("swarm stats works", func(t *testing.T) {
112 + t.Parallel()
113 res := node.RunIPFS("swarm", "resources", "--enc=json")
114 require.Equal(t, 0, res.ExitCode())
115
@@ -123,6 +127,7 @@ func TestRcmgr(t *testing.T) {
127 })
128
129 t.Run("smoke test transient scope", func(t *testing.T) {
130 + t.Parallel()
131 node := harness.NewT(t).NewNode().Init()
132 node.UpdateUserSuppliedResourceManagerOverrides(func(overrides *rcmgr.PartialLimitConfig) {
133 overrides.Transient.Memory = 88888
@@ -135,6 +140,7 @@ func TestRcmgr(t *testing.T) {
140 })
141
142 t.Run("smoke test service scope", func(t *testing.T) {
143 + t.Parallel()
144 node := harness.NewT(t).NewNode().Init()
145 node.UpdateUserSuppliedResourceManagerOverrides(func(overrides *rcmgr.PartialLimitConfig) {
146 overrides.Service = map[string]rcmgr.ResourceLimits{"foo": {Memory: 77777}}
@@ -147,6 +153,7 @@ func TestRcmgr(t *testing.T) {
153 })
154
155 t.Run("smoke test protocol scope", func(t *testing.T) {
156 + t.Parallel()
157 node := harness.NewT(t).NewNode().Init()
158 node.UpdateUserSuppliedResourceManagerOverrides(func(overrides *rcmgr.PartialLimitConfig) {
159 overrides.Protocol = map[protocol.ID]rcmgr.ResourceLimits{"foo": {Memory: 66666}}
@@ -159,6 +166,7 @@ func TestRcmgr(t *testing.T) {
166 })
167
168 t.Run("smoke test peer scope", func(t *testing.T) {
169 + t.Parallel()
170 validPeerID, err := peer.Decode("QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN")
171 assert.NoError(t, err)
172 node := harness.NewT(t).NewNode().Init()
@@ -172,13 +180,17 @@ func TestRcmgr(t *testing.T) {
180 assert.Equal(t, rcmgr.LimitVal64(55555), limits.Peers[validPeerID].Memory)
181 })
182
175 - t.Run("", func(t *testing.T) {
183 + t.Run("blocking and allowlists", func(t *testing.T) {
184 + t.Parallel()
185 nodes := harness.NewT(t).NewNodes(3).Init()
186 node0, node1, node2 := nodes[0], nodes[1], nodes[2]
178 - // peerID0, peerID1, peerID2 := node0.PeerID(), node1.PeerID(), node2.PeerID()
187 peerID1, peerID2 := node1.PeerID().String(), node2.PeerID().String()
188
181 - node0.UpdateConfigAndUserSuppliedResourceManagerOverrides(func(cfg *config.Config, overrides *rcmgr.PartialLimitConfig) {
189 + node0.UpdateConfig(func(cfg *config.Config) {
190 + cfg.Swarm.ResourceMgr.Enabled = config.True
191 + cfg.Swarm.ResourceMgr.Allowlist = []string{"/ip4/0.0.0.0/ipcidr/0/p2p/" + peerID2}
192 + })
193 + node0.UpdateUserSuppliedResourceManagerOverrides(func(overrides *rcmgr.PartialLimitConfig) {
194 *overrides = rcmgr.PartialLimitConfig{
195 System: rcmgr.ResourceLimits{
196 Conns: rcmgr.BlockAllLimit,
@@ -186,91 +198,97 @@ func TestRcmgr(t *testing.T) {
198 ConnsOutbound: rcmgr.BlockAllLimit,
199 },
200 }
189 - cfg.Swarm.ResourceMgr.Enabled = config.True
190 - cfg.Swarm.ResourceMgr.Allowlist = []string{"/ip4/0.0.0.0/ipcidr/0/p2p/" + peerID2}
201 })
202
203 nodes.StartDaemons()
204
195 - t.Parallel()
196 - t.Run("node 0 should fail to connect to node 1", func(t *testing.T) {
205 + t.Run("node 0 should fail to connect to and ping node 1", func(t *testing.T) {
206 + t.Parallel()
207 res := node0.Runner.Run(harness.RunRequest{
208 Path: node0.IPFSBin,
199 - Args: []string{"swarm", "connect", node1.SwarmAddrs()[0].String()},
209 + Args: []string{"swarm", "connect", node1.SwarmAddrsWithPeerIDs()[0].String()},
210 })
211 assert.Equal(t, 1, res.ExitCode())
212 assert.Contains(t, res.Stderr.String(), "failed to find any peer in table")
213 +
214 + res = node0.RunIPFS("ping", "-n2", peerID1)
215 + assert.Equal(t, 1, res.ExitCode())
216 + assert.Contains(t, res.Stderr.String(), "Error: ping failed")
217 })
218
205 - t.Run("node 0 should connect to node 2 since it is allowlisted", func(t *testing.T) {
219 + t.Run("node 0 should connect to and ping node 2 since it is allowlisted", func(t *testing.T) {
220 + t.Parallel()
221 res := node0.Runner.Run(harness.RunRequest{
222 Path: node0.IPFSBin,
208 - Args: []string{"swarm", "connect", node2.SwarmAddrs()[0].String()},
223 + Args: []string{"swarm", "connect", node2.SwarmAddrsWithPeerIDs()[0].String()},
224 })
225 assert.Equal(t, 0, res.ExitCode())
211 - })
226
213 - t.Run("node 0 should fail to ping node 1", func(t *testing.T) {
214 - res := node0.RunIPFS("ping", "-n2", peerID1)
215 - assert.Equal(t, 1, res.ExitCode())
216 - assert.Contains(t, res.Stderr.String(), "Error: ping failed")
217 - })
218 -
219 - t.Run("node 0 should be able to ping node 2", func(t *testing.T) {
220 - res := node0.RunIPFS("ping", "-n2", peerID2)
227 + res = node0.RunIPFS("ping", "-n2", peerID2)
228 assert.Equal(t, 0, res.ExitCode())
229 })
230 })
231
232 t.Run("daemon should refuse to start if connmgr.highwater < resources inbound", func(t *testing.T) {
226 - t.Parallel()
233 t.Run("system conns", func(t *testing.T) {
234 + t.Parallel()
235 node := harness.NewT(t).NewNode().Init()
229 - node.UpdateConfigAndUserSuppliedResourceManagerOverrides(func(cfg *config.Config, overrides *rcmgr.PartialLimitConfig) {
236 + node.UpdateConfig(func(cfg *config.Config) {
237 + cfg.Swarm.ConnMgr.HighWater = config.NewOptionalInteger(128)
238 + cfg.Swarm.ConnMgr.LowWater = config.NewOptionalInteger(64)
239 + })
240 + node.UpdateUserSuppliedResourceManagerOverrides(func(overrides *rcmgr.PartialLimitConfig) {
241 *overrides = rcmgr.PartialLimitConfig{
242 System: rcmgr.ResourceLimits{Conns: 128},
243 }
233 - cfg.Swarm.ConnMgr.HighWater = config.NewOptionalInteger(128)
234 - cfg.Swarm.ConnMgr.LowWater = config.NewOptionalInteger(64)
244 })
245
246 res := node.RunIPFS("daemon")
247 assert.Equal(t, 1, res.ExitCode())
248 })
249 t.Run("system conns inbound", func(t *testing.T) {
250 + t.Parallel()
251 node := harness.NewT(t).NewNode().Init()
242 - node.UpdateConfigAndUserSuppliedResourceManagerOverrides(func(cfg *config.Config, overrides *rcmgr.PartialLimitConfig) {
252 + node.UpdateConfig(func(cfg *config.Config) {
253 + cfg.Swarm.ConnMgr.HighWater = config.NewOptionalInteger(128)
254 + cfg.Swarm.ConnMgr.LowWater = config.NewOptionalInteger(64)
255 + })
256 + node.UpdateUserSuppliedResourceManagerOverrides(func(overrides *rcmgr.PartialLimitConfig) {
257 *overrides = rcmgr.PartialLimitConfig{
258 System: rcmgr.ResourceLimits{ConnsInbound: 128},
259 }
246 - cfg.Swarm.ConnMgr.HighWater = config.NewOptionalInteger(128)
247 - cfg.Swarm.ConnMgr.LowWater = config.NewOptionalInteger(64)
260 })
261
262 res := node.RunIPFS("daemon")
263 assert.Equal(t, 1, res.ExitCode())
264 })
265 t.Run("system streams", func(t *testing.T) {
266 + t.Parallel()
267 node := harness.NewT(t).NewNode().Init()
255 - node.UpdateConfigAndUserSuppliedResourceManagerOverrides(func(cfg *config.Config, overrides *rcmgr.PartialLimitConfig) {
268 + node.UpdateConfig(func(cfg *config.Config) {
269 + cfg.Swarm.ConnMgr.HighWater = config.NewOptionalInteger(128)
270 + cfg.Swarm.ConnMgr.LowWater = config.NewOptionalInteger(64)
271 + })
272 + node.UpdateUserSuppliedResourceManagerOverrides(func(overrides *rcmgr.PartialLimitConfig) {
273 *overrides = rcmgr.PartialLimitConfig{
274 System: rcmgr.ResourceLimits{Streams: 128},
275 }
259 - cfg.Swarm.ConnMgr.HighWater = config.NewOptionalInteger(128)
260 - cfg.Swarm.ConnMgr.LowWater = config.NewOptionalInteger(64)
276 })
277
278 res := node.RunIPFS("daemon")
279 assert.Equal(t, 1, res.ExitCode())
280 })
281 t.Run("system streams inbound", func(t *testing.T) {
282 + t.Parallel()
283 node := harness.NewT(t).NewNode().Init()
268 - node.UpdateConfigAndUserSuppliedResourceManagerOverrides(func(cfg *config.Config, overrides *rcmgr.PartialLimitConfig) {
284 + node.UpdateConfig(func(cfg *config.Config) {
285 + cfg.Swarm.ConnMgr.HighWater = config.NewOptionalInteger(128)
286 + cfg.Swarm.ConnMgr.LowWater = config.NewOptionalInteger(64)
287 + })
288 + node.UpdateUserSuppliedResourceManagerOverrides(func(overrides *rcmgr.PartialLimitConfig) {
289 *overrides = rcmgr.PartialLimitConfig{
290 System: rcmgr.ResourceLimits{StreamsInbound: 128},
291 }
272 - cfg.Swarm.ConnMgr.HighWater = config.NewOptionalInteger(128)
273 - cfg.Swarm.ConnMgr.LowWater = config.NewOptionalInteger(64)
292 })
293
294 res := node.RunIPFS("daemon")