Commit cfd24d85 authored by Luke Champine's avatar Luke Champine

add Close method to Contractor

parent f095e058
......@@ -124,6 +124,12 @@ func (c *Contractor) ResolveID(id types.FileContractID) types.FileContractID {
return id
}
// Close closes the Contractor.
func (c *Contractor) Close() error {
c.log.Close()
return c.persist.Close()
}
// New returns a new Contractor.
func New(cs consensusSet, wallet walletShim, tpool transactionPool, hdb hostDB, persistDir string) (*Contractor, error) {
// Check for nil inputs.
......
......@@ -55,6 +55,7 @@ type (
save(contractorPersist) error
update(...journalUpdate) error
load(*contractorPersist) error
Close() error
}
)
......@@ -100,6 +101,10 @@ func (p *stdPersist) load(data *contractorPersist) error {
return err
}
func (p stdPersist) Close() error {
return p.journal.Close()
}
func newPersist(dir string) *stdPersist {
return &stdPersist{
filename: filepath.Join(dir, "contractor.journal"),
......
......@@ -187,6 +187,7 @@ func TestIntegrationFormContract(t *testing.T) {
t.Fatal(err)
}
defer h.Close()
defer c.Close()
// get the host's entry from the db
hostEntry, ok := c.hdb.Host(h.PublicKey())
......@@ -214,6 +215,7 @@ func TestIntegrationReviseContract(t *testing.T) {
t.Fatal(err)
}
defer h.Close()
defer c.Close()
// get the host's entry from the db
hostEntry, ok := c.hdb.Host(h.PublicKey())
......@@ -262,6 +264,7 @@ func TestIntegrationUploadDownload(t *testing.T) {
t.Fatal(err)
}
defer h.Close()
defer c.Close()
// get the host's entry from the db
hostEntry, ok := c.hdb.Host(h.PublicKey())
......@@ -325,6 +328,7 @@ func TestIntegrationDelete(t *testing.T) {
t.Fatal(err)
}
defer h.Close()
defer c.Close()
// get the host's entry from the db
hostEntry, ok := c.hdb.Host(h.PublicKey())
......@@ -388,6 +392,7 @@ func TestIntegrationInsertDelete(t *testing.T) {
t.Fatal(err)
}
defer h.Close()
defer c.Close()
// get the host's entry from the db
hostEntry, ok := c.hdb.Host(h.PublicKey())
......@@ -448,6 +453,7 @@ func TestIntegrationModify(t *testing.T) {
t.Fatal(err)
}
defer h.Close()
defer c.Close()
// get the host's entry from the db
hostEntry, ok := c.hdb.Host(h.PublicKey())
......@@ -515,6 +521,7 @@ func TestIntegrationRenew(t *testing.T) {
t.Fatal(err)
}
defer h.Close()
defer c.Close()
// get the host's entry from the db
hostEntry, ok := c.hdb.Host(h.PublicKey())
......@@ -642,6 +649,7 @@ func TestIntegrationResync(t *testing.T) {
t.Fatal(err)
}
defer h.Close()
defer c.Close()
// get the host's entry from the db
hostEntry, ok := c.hdb.Host(h.PublicKey())
......@@ -780,6 +788,7 @@ func TestIntegrationDownloaderCaching(t *testing.T) {
t.Fatal(err)
}
defer h.Close()
defer c.Close()
// get the host's entry from the db
hostEntry, ok := c.hdb.Host(h.PublicKey())
......@@ -873,6 +882,7 @@ func TestIntegrationEditorCaching(t *testing.T) {
t.Fatal(err)
}
defer h.Close()
defer c.Close()
// get the host's entry from the db
hostEntry, ok := c.hdb.Host(h.PublicKey())
......@@ -965,6 +975,7 @@ func TestIntegrationCachedRenew(t *testing.T) {
t.Fatal(err)
}
defer h.Close()
defer c.Close()
// get the host's entry from the db
hostEntry, ok := c.hdb.Host(h.PublicKey())
......
......@@ -18,6 +18,7 @@ type memPersist contractorPersist
func (m *memPersist) save(data contractorPersist) error { *m = memPersist(data); return nil }
func (m *memPersist) update(...journalUpdate) error { return nil }
func (m memPersist) load(data *contractorPersist) error { *data = contractorPersist(m); return nil }
func (m memPersist) Close() error { return nil }
// TestSaveLoad tests that the contractor can save and load itself.
func TestSaveLoad(t *testing.T) {
......
......@@ -80,6 +80,9 @@ type hostContractor interface {
// Allowance returns the current allowance
Allowance() modules.Allowance
// Close closes the hostContractor.
Close() error
// Contract returns the latest contract formed with the specified host.
Contract(modules.NetAddress) (modules.RenterContract, bool)
......@@ -220,7 +223,8 @@ func newRenter(cs modules.ConsensusSet, tpool modules.TransactionPool, hdb hostD
// Close closes the Renter and its dependencies
func (r *Renter) Close() error {
r.tg.Stop()
return r.hostDB.Close()
r.hostDB.Close()
return r.hostContractor.Close()
}
// PriceEstimation estimates the cost in siacoins of performing various storage
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment