func TestIntervalChunks_IteratorShare(t *testing.T) {
	desc := someDescriptors(0, 2)
	ps, db := newPullStorage(t, mock.WithSubscribePullChunks(desc...), mock.WithPartialInterval(true))

	go func() {
		// delay is needed in order to have the iterator
		// linger for a bit longer for more chunks.
		time.Sleep(200 * time.Millisecond)
		// add chunks to subscribe pull on the storage mock
		db.MorePull(someDescriptors(1, 3, 4)...)
	}()

	type result struct {
		addrs []swarm.Address
		top   uint64
	}
	sched := make(chan struct{})
	c := make(chan result)

	go func() {
		close(sched)
		addrs, topmost, err := ps.IntervalChunks(context.Background(), 0, 0, 5, limit)
		if err != nil {
			t.Errorf("internal goroutine: %v", err)
		}
		c <- result{addrs, topmost}

	}()
	<-sched // wait for goroutine to get scheduled

	addrs, topmost, err := ps.IntervalChunks(context.Background(), 0, 0, 5, limit)
	if err != nil {
		t.Fatal(err)
	}

	res := <-c

	if l := len(addrs); l != 5 {
		t.Fatalf("want %d addrs but got %d", 5, l)
	}

	// highest chunk we sent had BinID 5
	exp := uint64(5)
	if topmost != exp {
		t.Fatalf("expected topmost %d but got %d", exp, topmost)
	}
	if c := db.SubscribePullCalls(); c != 1 {
		t.Fatalf("wanted 1 subscribe pull calls, got %d", c)
	}

	// check that results point to same array
	sh := (*reflect.SliceHeader)(unsafe.Pointer(&res.addrs))
	sh2 := (*reflect.SliceHeader)(unsafe.Pointer(&addrs))

	if sh.Data != sh2.Data {
		t.Fatalf("results not shared between goroutines. ptr1 %d ptr2 %d", sh.Data, sh2.Data)
	}
}
// TestIntervalChunks_IteratorShare tests that two goroutines
// with the same subscription call the SubscribePull only once
// and that results are shared between both of them.
TestIntervalChunks_IteratorShare tests that two goroutines
with the same subscription call the SubscribePull only once
and that results are shared between both of them.
// TestIntervalChunks_IteratorShare tests that two goroutines // with the same subscription call the SubscribePull only once // and that results are shared between both of them .
func TestIntervalChunks_IteratorShare(t *testing.T) {
	desc := someDescriptors(0, 2)
	ps, db := newPullStorage(t, mock.WithSubscribePullChunks(desc...), mock.WithPartialInterval(true))
	go func() {
		time.Sleep(200 * time.Millisecond)
		db.MorePull(someDescriptors(1, 3, 4)...)
	}()
	type result struct {
		addrs []swarm.Address
		top   uint64
	}
	sched := make(chan struct{})
	c := make(chan result)
	go func() {
		close(sched)
		addrs, topmost, err := ps.IntervalChunks(context.Background(), 0, 0, 5, limit)
		if err != nil {
			t.Errorf("internal goroutine: %v", err)
		}
		c <- result{addrs, topmost}
	}()
	<-sched 
	addrs, topmost, err := ps.IntervalChunks(context.Background(), 0, 0, 5, limit)
	if err != nil {
		t.Fatal(err)
	}
	res := <-c
	if l := len(addrs); l != 5 {
		t.Fatalf("want %d addrs but got %d", 5, l)
	}
	exp := uint64(5)
	if topmost != exp {
		t.Fatalf("expected topmost %d but got %d", exp, topmost)
	}
	if c := db.SubscribePullCalls(); c != 1 {
		t.Fatalf("wanted 1 subscribe pull calls, got %d", c)
	}
	sh := (*reflect.SliceHeader)(unsafe.Pointer(&res.addrs))
	sh2 := (*reflect.SliceHeader)(unsafe.Pointer(&addrs))
	if sh.Data != sh2.Data {
		t.Fatalf("results not shared between goroutines. ptr1 %d ptr2 %d", sh.Data, sh2.Data)
	}
}
func TestIntervalChunks_IteratorShare ( t * testing . T ) { desc := someDescriptors ( 0 , 2 ) ps , db := newPullStorage ( t , mock . WithSubscribePullChunks ( desc ... ) , mock . WithPartialInterval ( true ) ) go func ( ) { time . Sleep ( 200 * time . Millisecond ) db . MorePull ( someDescriptors ( 1 , 3 , 4 ) ... ) } ( ) type result struct { addrs [ ] swarm . Address top uint64 } sched := make ( chan struct { } ) c := make ( chan result ) go func ( ) { close ( sched ) addrs , topmost , err := ps . IntervalChunks ( context . Background ( ) , 0 , 0 , 5 , limit ) if err != nil { t . Errorf ( " " , err ) } c <- result { addrs , topmost } } ( ) <- sched addrs , topmost , err := ps . IntervalChunks ( context . Background ( ) , 0 , 0 , 5 , limit ) if err != nil { t . Fatal ( err ) } res := <- c if l := len ( addrs ) ; l != 5 { t . Fatalf ( " " , 5 , l ) } exp := uint64 ( 5 ) if topmost != exp { t . Fatalf ( " " , exp , topmost ) } if c := db . SubscribePullCalls ( ) ; c != 1 { t . Fatalf ( " " , c ) } sh := ( * reflect . SliceHeader ) ( unsafe . Pointer ( & res . addrs ) ) sh2 := ( * reflect . SliceHeader ) ( unsafe . Pointer ( & addrs ) ) if sh . Data != sh2 . Data { t . Fatalf ( " " , sh . Data , sh2 . Data ) } }
TestIntervalChunks_IteratorShare tests that two goroutines
with the same subscription call the SubscribePull only once
and that results are shared between both of them.
TestIntervalChunks_IteratorShare tests that two goroutines with the same subscription call the SubscribePull only once and that results are shared between both of them .
// delay is needed in order to have the iterator // linger for a bit longer for more chunks. // add chunks to subscribe pull on the storage mock // wait for goroutine to get scheduled // highest chunk we sent had BinID 5 // check that results point to same array