github.com/johnathanhowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/modules/host/network_test.go (about)

     1  package host
     2  
     3  /*
     4  import (
     5  	"path/filepath"
     6  	"sync/atomic"
     7  	"testing"
     8  
     9  	"github.com/NebulousLabs/Sia/modules"
    10  )
    11  
    12  // TestRPCMetrics checks that the rpc tracking is counting incoming RPC cals.
    13  func TestRPCMetrics(t *testing.T) {
    14  	if testing.Short() {
    15  		t.SkipNow()
    16  	}
    17  	ht, err := newHostTester("TestRPCMetrics")
    18  	if err != nil {
    19  		t.Fatal(err)
    20  	}
    21  
    22  	// Upload a test file to get some metrics to increment.
    23  	_, err = ht.uploadFile("TestRPCMetrics - 1", renewDisabled)
    24  	if err != nil {
    25  		t.Fatal(err)
    26  	}
    27  	if atomic.LoadUint64(&ht.host.atomicReviseCalls) != 1 {
    28  		t.Error("expected to count a revise call")
    29  	}
    30  	if atomic.LoadUint64(&ht.host.atomicSettingsCalls) != 1 {
    31  		t.Error("expected to count a settings call")
    32  	}
    33  	if atomic.LoadUint64(&ht.host.atomicUploadCalls) != 1 {
    34  		t.Error("expected to count an upload call")
    35  	}
    36  
    37  	// Restart the host and check that the counts persist.
    38  	err = ht.host.Close()
    39  	if err != nil {
    40  		t.Fatal(err)
    41  	}
    42  	rebootHost, err := New(ht.cs, ht.tpool, ht.wallet, "localhost:0", filepath.Join(ht.persistDir, modules.HostDir))
    43  	if err != nil {
    44  		t.Fatal(err)
    45  	}
    46  	if atomic.LoadUint64(&rebootHost.atomicReviseCalls) != 1 {
    47  		t.Error("expected to count a revise call")
    48  	}
    49  	if atomic.LoadUint64(&rebootHost.atomicSettingsCalls) != 1 {
    50  		t.Error("expected to count a settings call")
    51  	}
    52  	if atomic.LoadUint64(&rebootHost.atomicUploadCalls) != 1 {
    53  		t.Error("expected to count an upload call")
    54  	}
    55  }
    56  */