Skip to content

Commit

Permalink
speed up gouging test
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Dec 19, 2024
1 parent 1654237 commit f963bc1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/test/e2e/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ func addStorageFolderToHost(ctx context.Context, hosts []*Host) error {
// the group
func announceHosts(hosts []*Host) error {
for _, host := range hosts {
settings := defaultHostSettings
settings := host.settings.Settings()
settings.NetAddress = host.rhp4Listener.Addr().(*net.TCPAddr).IP.String()
if err := host.UpdateSettings(settings); err != nil {
return err
Expand Down
21 changes: 16 additions & 5 deletions internal/test/e2e/gouging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,20 @@ func TestGouging(t *testing.T) {
w := cluster.Worker
tt := cluster.tt

// add hosts
// add hosts with short price table validity to speed up test
gs, err := b.GougingSettings(context.Background())
tt.OK(err)
gs.MinPriceTableValidity = api.DurationMS(10 * time.Second)
tt.OK(cluster.bs.UpdateGougingSettings(context.Background(), gs))

n := int(test.AutopilotConfig.Contracts.Amount)
tt.OKAll(cluster.AddHostsBlocking(n))
for i := 0; i < n; i++ {
h := cluster.NewHost()
settings := h.settings.Settings()
settings.PriceTableValidity = time.Duration(gs.MinPriceTableValidity)
h.UpdateSettings(settings)
cluster.AddHost(h)
}
cluster.WaitForAccounts()

// assert all hosts are usable
Expand Down Expand Up @@ -66,21 +77,21 @@ func TestGouging(t *testing.T) {
tt.OK(cluster.hosts[0].UpdateSettings(updated))

// update gouging settings
gs := test.GougingSettings
gs = test.GougingSettings
gs.MaxStoragePrice = settings.StoragePrice
if err := b.UpdateGougingSettings(context.Background(), gs); err != nil {
t.Fatal(err)
}

// make sure the price table expires so the worker is forced to fetch it
// again, this is necessary for the host to be considered price gouging
time.Sleep(defaultHostSettings.PriceTableValidity)
time.Sleep(time.Duration(gs.MinPriceTableValidity))

// assert all but one host are usable
h, err = b.UsableHosts(context.Background())
tt.OK(err)
if len(h) != n-1 {
t.Fatal("unexpected number of hosts", len(h))
t.Fatal("unexpected number of hosts", len(h), n-1)
}

// upload some data - should fail
Expand Down
1 change: 1 addition & 0 deletions internal/test/e2e/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func NewHost(privKey types.PrivateKey, cm *chain.Manager, dir string, network *c
settings.WithRHP2Port(uint16(rhp2Listener.Addr().(*net.TCPAddr).Port)),
settings.WithRHP3Port(uint16(rhp3Listener.Addr().(*net.TCPAddr).Port)),
settings.WithRHP4Port(uint16(rhp4Listener.Addr().(*net.TCPAddr).Port)),
settings.WithInitialSettings(defaultHostSettings),
)
if err != nil {
return nil, fmt.Errorf("failed to create settings manager: %w", err)
Expand Down

0 comments on commit f963bc1

Please sign in to comment.