@cryptotaxi247 / kubo / commits / 47b820150

test: don't panic on errors in async node construction

This commit was moved from ipfs/go-ipfs-http-client@95ce0f3949da47b2db92508b8c7b0a00f502682b

Łukasz Magiera committed Feb 21, 2019 at 14:46 UTC 47b820150bddb9868274ed2c6faf79c6b8cbe369
1 file changed +25 -10
client/httpapi/api_test.go
+25 -10
@@ -114,27 +114,32 @@ func (NodeProvider) makeAPISwarm(ctx context.Context, fullIdentity bool, n int)
114
115 wg.Add(len(nodes))
116 zero.Add(1)
117 + errs := make(chan error, len(nodes))
118
119 for i, nd := range nodes {
120 go func(i int, nd testbedi.Core) {
121 defer wg.Done()
122
123 if _, err := nd.Init(ctx, "--empty-repo"); err != nil {
123 - panic(err)
124 + errs <- err
125 + return
126 }
127
128 if _, err := nd.RunCmd(ctx, nil, "ipfs", "config", "--json", "Experimental.FilestoreEnabled", "true"); err != nil {
127 - panic(err)
129 + errs <- err
130 + return
131 }
132
133 if _, err := nd.Start(ctx, true, "--enable-pubsub-experiment", "--offline="+strconv.FormatBool(n == 1)); err != nil {
131 - panic(err)
134 + errs <- err
135 + return
136 }
137
138 if i > 0 {
139 zero.Wait()
140 if err := nd.Connect(ctx, nodes[0]); err != nil {
137 - panic(err)
141 + errs <- err
142 + return
143 }
144 } else {
145 zero.Done()
@@ -142,12 +147,14 @@ func (NodeProvider) makeAPISwarm(ctx context.Context, fullIdentity bool, n int)
147
148 addr, err := nd.APIAddr()
149 if err != nil {
145 - panic(err)
150 + errs <- err
151 + return
152 }
153
154 maddr, err := ma.NewMultiaddr(addr)
155 if err != nil {
150 - panic(err)
156 + errs <- err
157 + return
158 }
159
160 c := &gohttp.Client{
@@ -159,16 +166,19 @@ func (NodeProvider) makeAPISwarm(ctx context.Context, fullIdentity bool, n int)
166 }
167 apis[i], err = NewApiWithClient(maddr, c)
168 if err != nil {
162 - panic(err)
169 + errs <- err
170 + return
171 }
172
173 // empty node is pinned even with --empty-repo, we don't want that
174 emptyNode, err := iface.ParsePath("/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn")
175 if err != nil {
168 - panic(err)
176 + errs <- err
177 + return
178 }
179 if err := apis[i].Pin().Rm(ctx, emptyNode); err != nil {
171 - panic(err)
180 + errs <- err
181 + return
182 }
183 }(i, nd)
184 }
@@ -187,7 +197,12 @@ func (NodeProvider) makeAPISwarm(ctx context.Context, fullIdentity bool, n int)
197 }()
198 }()
199
190 - return apis, nil
200 + select {
201 + case err = <-errs:
202 + default:
203 + }
204 +
205 + return apis, err
206 }
207
208 func TestHttpApi(t *testing.T) {