github.com/avahowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/api/host_test.go (about) 1 package api 2 3 /* 4 // TestIntegrationRenewing tests that the renter and host manage contract 5 // renewals properly. 6 func TestIntegrationRenewing(t *testing.T) { 7 st, err := createServerTester("TestIntegrationRenewing") 8 if err != nil { 9 t.Fatal(err) 10 } 11 defer st.server.Close() 12 13 // Announce the host. 14 err = st.announceHost() 15 if err != nil { 16 t.Fatal(err) 17 } 18 19 // create a file 20 path := filepath.Join(build.SiaTestingDir, "api", "TestIntegrationRenewing", "test.dat") 21 err = createRandFile(path) 22 if err != nil { 23 t.Fatal(err) 24 } 25 26 // upload to host, specifying that the file should be renewed 27 uploadValues := url.Values{} 28 uploadValues.Set("source", path) 29 err = st.stdPostAPI("/renter/upload/test", uploadValues) 30 if err != nil { 31 t.Fatal(err) 32 } 33 // only one piece will be uploaded (10% at current redundancy) 34 var rf RenterFiles 35 for i := 0; i < 150 && (len(rf.Files) != 1 || rf.Files[0].UploadProgress != 10); i++ { 36 st.getAPI("/renter/files", &rf) 37 time.Sleep(50 * time.Millisecond) 38 } 39 if len(rf.Files) != 1 || rf.Files[0].UploadProgress != 10 { 40 t.Error(rf.Files[0].UploadProgress) 41 t.Fatal("uploading has failed") 42 } 43 44 // default expiration is 20 blocks 45 expExpiration := st.cs.Height() + 20 46 if rf.Files[0].Expiration != expExpiration { 47 t.Fatalf("expected expiration of %v, got %v", expExpiration, rf.Files[0].Expiration) 48 } 49 50 // mine blocks until we hit the renew threshold (default 10 blocks) 51 for st.cs.Height() < expExpiration-10 { 52 st.miner.AddBlock() 53 } 54 55 // renter should now renew the contract for another 20 blocks 56 newExpiration := st.cs.Height() + 20 57 for i := 0; i < 5 && rf.Files[0].Expiration != newExpiration; i++ { 58 time.Sleep(1 * time.Second) 59 st.getAPI("/renter/files", &rf) 60 } 61 } 62 */