Skip to content

Commit

Permalink
Merge pull request #1000 from SiaFoundation/pj/mock-bus
Browse files Browse the repository at this point in the history
Extend worker mocks
  • Loading branch information
ChrisSchinnerl authored Feb 28, 2024
2 parents 1771e41 + 9798d64 commit e031cf4
Show file tree
Hide file tree
Showing 31 changed files with 1,038 additions and 734 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
- name: Test Integration
uses: n8maninger/action-golang-test@v1
with:
package: "./internal/testing/..."
package: "./internal/test/e2e/..."
args: "-failfast;-race;-tags=testing;-timeout=30m"
- name: Test Integration - MySQL
if: matrix.os == 'ubuntu-latest'
Expand All @@ -70,7 +70,7 @@ jobs:
RENTERD_DB_USER: root
RENTERD_DB_PASSWORD: test
with:
package: "./internal/testing/..."
package: "./internal/test/e2e/..."
args: "-failfast;-race;-tags=testing;-timeout=30m"
- name: Build
run: go build -o bin/ ./cmd/renterd
2 changes: 1 addition & 1 deletion internal/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func NewBus(cfg BusConfig, dir string, seed types.PrivateKey, l *zap.Logger) (ht

func NewWorker(cfg config.Worker, b worker.Bus, seed types.PrivateKey, l *zap.Logger) (http.Handler, ShutdownFn, error) {
workerKey := blake2b.Sum256(append([]byte("worker"), seed...))
w, err := worker.New(workerKey, cfg.ID, b, cfg.ContractLockTimeout, cfg.BusFlushInterval, cfg.DownloadOverdriveTimeout, cfg.UploadOverdriveTimeout, cfg.DownloadMaxOverdrive, cfg.DownloadMaxMemory, cfg.UploadMaxMemory, cfg.UploadMaxOverdrive, cfg.AllowPrivateIPs, l)
w, err := worker.New(workerKey, cfg.ID, b, cfg.ContractLockTimeout, cfg.BusFlushInterval, cfg.DownloadOverdriveTimeout, cfg.UploadOverdriveTimeout, cfg.DownloadMaxOverdrive, cfg.UploadMaxOverdrive, cfg.DownloadMaxMemory, cfg.UploadMaxMemory, cfg.AllowPrivateIPs, l)
if err != nil {
return nil, nil, err
}
Expand Down
64 changes: 64 additions & 0 deletions internal/test/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package test

import (
"time"

"github.com/minio/minio-go/v7/pkg/credentials"
rhpv2 "go.sia.tech/core/rhp/v2"
"go.sia.tech/core/types"
"go.sia.tech/renterd/api"
)

var (
// AutopilotConfig is the autopilot used for testing unless a different
// one is explicitly set.
AutopilotConfig = api.AutopilotConfig{
Contracts: api.ContractsConfig{
Allowance: types.Siacoins(1).Mul64(1e3),
Amount: 3,
Period: 144,
RenewWindow: 72,

Download: rhpv2.SectorSize * 500,
Upload: rhpv2.SectorSize * 500,
Storage: rhpv2.SectorSize * 5e3,

Set: ContractSet,
Prune: false,
},
Hosts: api.HostsConfig{
MaxDowntimeHours: 10,
MinRecentScanFailures: 10,
AllowRedundantIPs: true, // allow for integration tests by default
},
}

ContractSet = "testset"
ContractSetSettings = api.ContractSetSetting{
Default: ContractSet,
}

GougingSettings = api.GougingSettings{
MinMaxCollateral: types.Siacoins(10), // at least up to 10 SC per contract
MaxRPCPrice: types.Siacoins(1).Div64(1000), // 1mS per RPC
MaxContractPrice: types.Siacoins(10), // 10 SC per contract
MaxDownloadPrice: types.Siacoins(1).Mul64(1000), // 1000 SC per 1 TiB
MaxUploadPrice: types.Siacoins(1).Mul64(1000), // 1000 SC per 1 TiB
MaxStoragePrice: types.Siacoins(1000).Div64(144 * 30), // 1000 SC per month

HostBlockHeightLeeway: 240, // amount of leeway given to host block height

MinPriceTableValidity: 10 * time.Second, // minimum value for price table validity
MinAccountExpiry: time.Hour, // minimum value for account expiry
MinMaxEphemeralAccountBalance: types.Siacoins(1), // 1SC
}

RedundancySettings = api.RedundancySettings{
MinShards: 2,
TotalShards: 3,
}

S3AccessKeyID = "TESTINGYNHUWCPKOPSYQ"
S3SecretAccessKey = "Rh30BNyj+qNI4ftYRteoZbHJ3X4Ln71QtZkRXzJ9"
S3Credentials = credentials.NewStaticV4(S3AccessKeyID, S3SecretAccessKey, "")
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testing
package e2e

import (
"context"
Expand All @@ -8,6 +8,7 @@ import (

"go.sia.tech/core/types"
"go.sia.tech/renterd/api"
"go.sia.tech/renterd/internal/test"
)

func TestBlocklist(t *testing.T) {
Expand All @@ -26,7 +27,7 @@ func TestBlocklist(t *testing.T) {
tt := cluster.tt

// fetch contracts
contracts, err := b.Contracts(ctx, api.ContractsOpts{ContractSet: testAutopilotConfig.Contracts.Set})
contracts, err := b.Contracts(ctx, api.ContractsOpts{ContractSet: test.AutopilotConfig.Contracts.Set})
tt.OK(err)
if len(contracts) != 3 {
t.Fatalf("unexpected number of contracts, %v != 3", len(contracts))
Expand All @@ -40,7 +41,7 @@ func TestBlocklist(t *testing.T) {

// assert h3 is no longer in the contract set
tt.Retry(5, time.Second, func() error {
contracts, err := b.Contracts(ctx, api.ContractsOpts{ContractSet: testAutopilotConfig.Contracts.Set})
contracts, err := b.Contracts(ctx, api.ContractsOpts{ContractSet: test.AutopilotConfig.Contracts.Set})
tt.OK(err)
if len(contracts) != 2 {
return fmt.Errorf("unexpected number of contracts, %v != 2", len(contracts))
Expand All @@ -60,7 +61,7 @@ func TestBlocklist(t *testing.T) {

// assert h1 is no longer in the contract set
tt.Retry(5, time.Second, func() error {
contracts, err := b.Contracts(ctx, api.ContractsOpts{ContractSet: testAutopilotConfig.Contracts.Set})
contracts, err := b.Contracts(ctx, api.ContractsOpts{ContractSet: test.AutopilotConfig.Contracts.Set})
tt.OK(err)
if len(contracts) != 1 {
return fmt.Errorf("unexpected number of contracts, %v != 1", len(contracts))
Expand All @@ -77,7 +78,7 @@ func TestBlocklist(t *testing.T) {
tt.OK(b.UpdateHostAllowlist(ctx, nil, []types.PublicKey{hk1, hk2}, false))
tt.OK(b.UpdateHostBlocklist(ctx, nil, []string{h1.NetAddress}, false))
tt.Retry(5, time.Second, func() error {
contracts, err := b.Contracts(ctx, api.ContractsOpts{ContractSet: testAutopilotConfig.Contracts.Set})
contracts, err := b.Contracts(ctx, api.ContractsOpts{ContractSet: test.AutopilotConfig.Contracts.Set})
tt.OK(err)
if len(contracts) != 3 {
return fmt.Errorf("unexpected number of contracts, %v != 3", len(contracts))
Expand Down
Loading

0 comments on commit e031cf4

Please sign in to comment.