| 162 | } |
| 163 | |
| 164 | func 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) |