From ecddd080484cf6582283179e62ca00f6a8953968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 3 Aug 2022 13:05:30 +0200 Subject: [PATCH] itests: Test custom worker names --- itests/kit/ensemble.go | 1 + itests/kit/node_opts.go | 8 ++++++++ itests/worker_test.go | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/itests/kit/ensemble.go b/itests/kit/ensemble.go index 124e8ddb2..434917c54 100644 --- a/itests/kit/ensemble.go +++ b/itests/kit/ensemble.go @@ -727,6 +727,7 @@ func (n *Ensemble) Start() *Ensemble { LocalWorker: sectorstorage.NewLocalWorker(sectorstorage.WorkerConfig{ TaskTypes: m.options.workerTasks, NoSwap: false, + Name: m.options.workerName, }, store, localStore, m.MinerNode, m.MinerNode, wsts), LocalStore: localStore, Storage: lr, diff --git a/itests/kit/node_opts.go b/itests/kit/node_opts.go index 0fe66eaea..8a08d8879 100644 --- a/itests/kit/node_opts.go +++ b/itests/kit/node_opts.go @@ -47,6 +47,7 @@ type nodeOpts struct { workerTasks []sealtasks.TaskType workerStorageOpt func(paths.Store) paths.Store + workerName string } // DefaultNodeOpts are the default options that will be applied to test nodes. @@ -219,6 +220,13 @@ func WithTaskTypes(tt []sealtasks.TaskType) NodeOpt { } } +func WithWorkerName(n string) NodeOpt { + return func(opts *nodeOpts) error { + opts.workerName = n + return nil + } +} + var WithSealWorkerTasks = WithTaskTypes([]sealtasks.TaskType{sealtasks.TTFetch, sealtasks.TTCommit1, sealtasks.TTFinalize, sealtasks.TTAddPiece, sealtasks.TTPreCommit1, sealtasks.TTPreCommit2, sealtasks.TTCommit2, sealtasks.TTUnseal}) func WithWorkerStorage(transform func(paths.Store) paths.Store) NodeOpt { diff --git a/itests/worker_test.go b/itests/worker_test.go index 7328bd50f..19bb763fc 100644 --- a/itests/worker_test.go +++ b/itests/worker_test.go @@ -401,3 +401,28 @@ func TestWindowPostWorkerManualPoSt(t *testing.T) { require.NoError(t, err) require.Len(t, lastPending, 0) } + +func TestWorkerName(t *testing.T) { + name := "thisstringisprobablynotahostnameihope" + + ctx := context.Background() + _, miner, worker, ens := kit.EnsembleWorker(t, kit.WithAllSubsystems(), kit.ThroughRPC(), kit.WithWorkerName(name)) + + ens.InterconnectAll().BeginMining(50 * time.Millisecond) + + e, err := worker.Info(ctx) + require.NoError(t, err) + require.Equal(t, name, e.Hostname) + + ws, err := miner.WorkerStats(ctx) + require.NoError(t, err) + + var found bool + for _, stats := range ws { + if stats.Info.Hostname == name { + found = true + } + } + + require.True(t, found) +}