fb4812ec79
This fixes #326. It adds a new `pin_method` configuration option to the `ipfshttp` component allows to configure it to perform `refs -r <cid>` before the `pin/add` call. By fetching content before pinning, we don't have a global lock in place, and we can have several pin-requests to ipfs in parallel. It also adds a `concurrent_pins` option to the pin tracker, which launches more pin workers so it can potentially trigger more pins at the same time. This is a minimal intervention in the pintracker as #308 is still pending. Documentation for the configuration file has been updated. License: MIT Signed-off-by: Hector Sanjuan <code@hector.link>
112 lines
2.1 KiB
Go
112 lines
2.1 KiB
Go
package ipfshttp
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
var cfgJSON = []byte(`
|
|
{
|
|
"proxy_listen_multiaddress": "/ip4/127.0.0.1/tcp/9095",
|
|
"node_multiaddress": "/ip4/127.0.0.1/tcp/5001",
|
|
"connect_swarms_delay": "7s",
|
|
"proxy_read_timeout": "10m0s",
|
|
"proxy_read_header_timeout": "5s",
|
|
"proxy_write_timeout": "10m0s",
|
|
"proxy_idle_timeout": "1m0s",
|
|
"pin_method": "pin"
|
|
}
|
|
`)
|
|
|
|
func TestLoadJSON(t *testing.T) {
|
|
cfg := &Config{}
|
|
err := cfg.LoadJSON(cfgJSON)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
j := &jsonConfig{}
|
|
json.Unmarshal(cfgJSON, j)
|
|
j.ProxyListenMultiaddress = "abc"
|
|
tst, _ := json.Marshal(j)
|
|
err = cfg.LoadJSON(tst)
|
|
if err == nil {
|
|
t.Error("expected error decoding proxy_listen_multiaddress")
|
|
}
|
|
|
|
j = &jsonConfig{}
|
|
json.Unmarshal(cfgJSON, j)
|
|
j.NodeMultiaddress = "abc"
|
|
tst, _ = json.Marshal(j)
|
|
err = cfg.LoadJSON(tst)
|
|
if err == nil {
|
|
t.Error("expected error in node_multiaddress")
|
|
}
|
|
|
|
j = &jsonConfig{}
|
|
json.Unmarshal(cfgJSON, j)
|
|
j.ProxyReadTimeout = "-aber"
|
|
tst, _ = json.Marshal(j)
|
|
err = cfg.LoadJSON(tst)
|
|
if err == nil {
|
|
t.Error("expected error in proxy_read_timeout")
|
|
}
|
|
}
|
|
|
|
func TestToJSON(t *testing.T) {
|
|
cfg := &Config{}
|
|
cfg.LoadJSON(cfgJSON)
|
|
newjson, err := cfg.ToJSON()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cfg = &Config{}
|
|
err = cfg.LoadJSON(newjson)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestDefault(t *testing.T) {
|
|
cfg := &Config{}
|
|
cfg.Default()
|
|
if cfg.Validate() != nil {
|
|
t.Fatal("error validating")
|
|
}
|
|
|
|
cfg.NodeAddr = nil
|
|
if cfg.Validate() == nil {
|
|
t.Fatal("expected error validating")
|
|
}
|
|
|
|
cfg.Default()
|
|
cfg.ProxyAddr = nil
|
|
if cfg.Validate() == nil {
|
|
t.Fatal("expected error validating")
|
|
}
|
|
|
|
cfg.Default()
|
|
cfg.ProxyReadTimeout = -1
|
|
if cfg.Validate() == nil {
|
|
t.Fatal("expected error validating")
|
|
}
|
|
|
|
cfg.Default()
|
|
cfg.ProxyReadHeaderTimeout = -2
|
|
if cfg.Validate() == nil {
|
|
t.Fatal("expected error validating")
|
|
}
|
|
|
|
cfg.Default()
|
|
cfg.ProxyIdleTimeout = -1
|
|
if cfg.Validate() == nil {
|
|
t.Fatal("expected error validating")
|
|
}
|
|
|
|
cfg.Default()
|
|
cfg.ProxyWriteTimeout = -3
|
|
if cfg.Validate() == nil {
|
|
t.Fatal("expected error validating")
|
|
}
|
|
}
|