mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
swarm/storage: Correct channel for waiting on chunk put
This commit is contained in:
parent
0455925ebf
commit
a32681cba4
3 changed files with 26 additions and 12 deletions
|
|
@ -23,17 +23,23 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/swarm/api"
|
||||
swarm "github.com/ethereum/go-ethereum/swarm/api/client"
|
||||
"github.com/ethereum/go-ethereum/swarm/storage"
|
||||
"github.com/ethereum/go-ethereum/swarm/testutil"
|
||||
)
|
||||
|
||||
func init() {
|
||||
log.Root().SetHandler(log.CallerFileHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))))
|
||||
}
|
||||
|
||||
// \TODO if create -> get -> update -> get, the last get with return 1.1 because 1.2 retrieve is still pending
|
||||
func TestBzzResource(t *testing.T) {
|
||||
srv := testutil.NewTestSwarmServer(t)
|
||||
|
|
@ -64,6 +70,22 @@ func TestBzzResource(t *testing.T) {
|
|||
}
|
||||
resp.Body.Close()
|
||||
|
||||
// get latest update (1.1) through resource directly
|
||||
url = fmt.Sprintf("%s/bzz-resource:/%x", srv.URL, keybytes)
|
||||
resp, err = http.Get(url)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("err %s", resp.Status)
|
||||
}
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !bytes.Equal(databytes, b) {
|
||||
t.Fatalf("Expected body '%x', got '%x'", databytes, b)
|
||||
}
|
||||
resp.Body.Close()
|
||||
|
||||
// update 2
|
||||
url = fmt.Sprintf("%s/bzz-resource:/%x", srv.URL, keybytes)
|
||||
data := []byte("foo")
|
||||
|
|
@ -82,7 +104,7 @@ func TestBzzResource(t *testing.T) {
|
|||
} else if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("err %s", resp.Status)
|
||||
}
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
b, err = ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !bytes.Equal(data, b) {
|
||||
|
|
|
|||
|
|
@ -752,14 +752,16 @@ func (r *resourceChunkStore) Get(key Key) (*Chunk, error) {
|
|||
select {
|
||||
case <-t.C:
|
||||
return nil, errors.New("timeout")
|
||||
case <-chunk.C:
|
||||
case <-chunk.Req.C:
|
||||
log.Trace("Received resource update chunk", "peer", chunk.Req.Source)
|
||||
}
|
||||
return chunk, nil
|
||||
}
|
||||
|
||||
func (r *resourceChunkStore) Put(chunk *Chunk) {
|
||||
chunk.wg = &sync.WaitGroup{}
|
||||
r.netStore.Put(chunk)
|
||||
chunk.wg.Wait()
|
||||
}
|
||||
|
||||
func (r *resourceChunkStore) Close() {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import (
|
|||
"math/big"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
|
|
@ -117,12 +116,3 @@ func (c *testCloudStore) Deliver(*storage.Chunk) {
|
|||
|
||||
func (c *testCloudStore) Retrieve(*storage.Chunk) {
|
||||
}
|
||||
|
||||
// for faking the rpc service, since we don't need the whole node stack
|
||||
type FakeRPC struct {
|
||||
blocknumber uint64
|
||||
}
|
||||
|
||||
func (r *FakeRPC) BlockNumber() (string, error) {
|
||||
return strconv.FormatUint(r.blocknumber, 10), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue