Skip to content
This repository was archived by the owner on Oct 5, 2023. It is now read-only.

Commit 95ce0f3

Browse files
committed
test: don't panic on errors in async node construction
1 parent b7db17c commit 95ce0f3

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

api_test.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,40 +114,47 @@ func (NodeProvider) makeAPISwarm(ctx context.Context, fullIdentity bool, n int)
114114

115115
wg.Add(len(nodes))
116116
zero.Add(1)
117+
errs := make(chan error, len(nodes))
117118

118119
for i, nd := range nodes {
119120
go func(i int, nd testbedi.Core) {
120121
defer wg.Done()
121122

122123
if _, err := nd.Init(ctx, "--empty-repo"); err != nil {
123-
panic(err)
124+
errs <- err
125+
return
124126
}
125127

126128
if _, err := nd.RunCmd(ctx, nil, "ipfs", "config", "--json", "Experimental.FilestoreEnabled", "true"); err != nil {
127-
panic(err)
129+
errs <- err
130+
return
128131
}
129132

130133
if _, err := nd.Start(ctx, true, "--enable-pubsub-experiment", "--offline="+strconv.FormatBool(n == 1)); err != nil {
131-
panic(err)
134+
errs <- err
135+
return
132136
}
133137

134138
if i > 0 {
135139
zero.Wait()
136140
if err := nd.Connect(ctx, nodes[0]); err != nil {
137-
panic(err)
141+
errs <- err
142+
return
138143
}
139144
} else {
140145
zero.Done()
141146
}
142147

143148
addr, err := nd.APIAddr()
144149
if err != nil {
145-
panic(err)
150+
errs <- err
151+
return
146152
}
147153

148154
maddr, err := ma.NewMultiaddr(addr)
149155
if err != nil {
150-
panic(err)
156+
errs <- err
157+
return
151158
}
152159

153160
c := &gohttp.Client{
@@ -159,16 +166,19 @@ func (NodeProvider) makeAPISwarm(ctx context.Context, fullIdentity bool, n int)
159166
}
160167
apis[i], err = NewApiWithClient(maddr, c)
161168
if err != nil {
162-
panic(err)
169+
errs <- err
170+
return
163171
}
164172

165173
// empty node is pinned even with --empty-repo, we don't want that
166174
emptyNode, err := iface.ParsePath("/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn")
167175
if err != nil {
168-
panic(err)
176+
errs <- err
177+
return
169178
}
170179
if err := apis[i].Pin().Rm(ctx, emptyNode); err != nil {
171-
panic(err)
180+
errs <- err
181+
return
172182
}
173183
}(i, nd)
174184
}
@@ -187,7 +197,12 @@ func (NodeProvider) makeAPISwarm(ctx context.Context, fullIdentity bool, n int)
187197
}()
188198
}()
189199

190-
return apis, nil
200+
select {
201+
case err = <-errs:
202+
default:
203+
}
204+
205+
return apis, err
191206
}
192207

193208
func TestHttpApi(t *testing.T) {

0 commit comments

Comments
 (0)