MCPcopy
hub / github.com/ipfs/kubo / TestAddGCLive

Function TestAddGCLive

core/coreunix/add_test.go:164–271  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

162}
163
164func TestAddGCLive(t *testing.T) {
165 ctx := t.Context()
166 r := &repo.Mock{
167 C: config.Config{
168 Identity: config.Identity{
169 PeerID: testPeerID, // required by offline node
170 },
171 },
172 D: syncds.MutexWrap(datastore.NewMapDatastore()),
173 }
174 node, err := core.NewNode(ctx, &core.BuildCfg{Repo: r})
175 if err != nil {
176 t.Fatal(err)
177 }
178
179 out := make(chan any)
180 adder, err := NewAdder(ctx, node.Pinning, node.Blockstore, node.DAG)
181 if err != nil {
182 t.Fatal(err)
183 }
184 adder.Out = out
185
186 rfa := files.NewBytesFile([]byte("testfileA"))
187
188 // make two files with pipes so we can 'pause' the add for timing of the test
189 piper, pipew := io.Pipe()
190 hangfile := files.NewReaderFile(piper)
191
192 rfd := files.NewBytesFile([]byte("testfileD"))
193
194 slf := files.NewMapDirectory(map[string]files.Node{
195 "a": rfa,
196 "b": hangfile,
197 "d": rfd,
198 })
199
200 addDone := make(chan struct{})
201 go func() {
202 defer close(addDone)
203 defer close(out)
204 _, err := adder.AddAllAndPin(ctx, slf)
205 if err != nil {
206 t.Error(err)
207 }
208 }()
209
210 addedHashes := make(map[string]struct{})
211 select {
212 case o := <-out:
213 addedHashes[o.(*coreiface.AddEvent).Path.RootCid().String()] = struct{}{}
214 case <-addDone:
215 t.Fatal("add shouldn't complete yet")
216 }
217
218 var gcout <-chan gc.Result
219 gcstarted := make(chan struct{})
220 go func() {
221 defer close(gcstarted)

Callers

nothing calls this directly

Calls 11

AddAllAndPinMethod · 0.95
NewNodeFunction · 0.92
GCFunction · 0.92
NewAdderFunction · 0.85
FatalMethod · 0.80
ContextMethod · 0.65
DatastoreMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45
StringMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected