github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/test/devstack/min_bids_test.go (about)

     1  //go:build integration
     2  
     3  package devstack
     4  
     5  import (
     6  	"testing"
     7  
     8  	"github.com/filecoin-project/bacalhau/pkg/devstack"
     9  
    10  	"github.com/filecoin-project/bacalhau/pkg/job"
    11  	_ "github.com/filecoin-project/bacalhau/pkg/logger"
    12  	"github.com/filecoin-project/bacalhau/pkg/model"
    13  	"github.com/filecoin-project/bacalhau/pkg/test/scenario"
    14  	"github.com/stretchr/testify/suite"
    15  )
    16  
    17  type MinBidsSuite struct {
    18  	scenario.ScenarioRunner
    19  }
    20  
    21  // In order for 'go test' to run this suite, we need to create
    22  // a normal test function and pass our suite to suite.Run
    23  func TestMinBidsSuite(t *testing.T) {
    24  	suite.Run(t, new(MinBidsSuite))
    25  }
    26  
    27  type minBidsTestCase struct {
    28  	nodes          int
    29  	shards         int
    30  	concurrency    int
    31  	minBids        int
    32  	expectedResult map[model.ExecutionStateType]int
    33  	submitChecker  scenario.CheckSubmitResponse
    34  	errorStates    []model.ExecutionStateType
    35  }
    36  
    37  func (s *MinBidsSuite) testMinBids(testCase minBidsTestCase) {
    38  	spec := scenario.WasmHelloWorld.Spec
    39  	spec.Sharding = model.JobShardingConfig{
    40  		GlobPattern: "/input/*",
    41  		BatchSize:   1,
    42  	}
    43  
    44  	testScenario := scenario.Scenario{
    45  		Stack: &scenario.StackConfig{
    46  			DevStackOptions: &devstack.DevStackOptions{NumberOfHybridNodes: testCase.nodes},
    47  		},
    48  		Inputs: scenario.StoredFile(
    49  			prepareFolderWithFiles(s.T(), testCase.shards),
    50  			"/input",
    51  		),
    52  		Spec: spec,
    53  		Deal: model.Deal{
    54  			Concurrency: testCase.concurrency,
    55  			MinBids:     testCase.minBids,
    56  		},
    57  		JobCheckers: []job.CheckStatesFunction{
    58  			job.WaitExecutionsThrowErrors(testCase.errorStates),
    59  			job.WaitForExecutionStates(testCase.expectedResult),
    60  		},
    61  		SubmitChecker: testCase.submitChecker,
    62  	}
    63  
    64  	s.RunScenario(testScenario)
    65  }
    66  
    67  func (s *MinBidsSuite) TestMinBids_0and1Node() {
    68  	// sanity test that with min bids at zero and 1 node we get the job through
    69  	s.testMinBids(minBidsTestCase{
    70  		nodes:       1,
    71  		shards:      1,
    72  		concurrency: 1,
    73  		minBids:     0,
    74  		expectedResult: map[model.ExecutionStateType]int{
    75  			model.ExecutionStateCompleted: 1,
    76  		},
    77  		errorStates: []model.ExecutionStateType{
    78  			model.ExecutionStateFailed,
    79  		},
    80  	})
    81  }
    82  
    83  func (s *MinBidsSuite) TestMinBids_isConcurrency() {
    84  	// test that when min bids is concurrency we get the job through
    85  	s.testMinBids(minBidsTestCase{
    86  		nodes:       3,
    87  		shards:      1,
    88  		concurrency: 3,
    89  		minBids:     3,
    90  		expectedResult: map[model.ExecutionStateType]int{
    91  			model.ExecutionStateCompleted: 3,
    92  		},
    93  		errorStates: []model.ExecutionStateType{
    94  			model.ExecutionStateFailed,
    95  		},
    96  	})
    97  
    98  }
    99  
   100  func (s *MinBidsSuite) TestMinBids_noBids() {
   101  	// test that no bids are made because there are not enough nodes on the network
   102  	// to satisfy the min bids
   103  	s.testMinBids(minBidsTestCase{
   104  		nodes:         3,
   105  		shards:        1,
   106  		concurrency:   3,
   107  		minBids:       5,
   108  		submitChecker: scenario.SubmitJobErrorContains("not enough"),
   109  	})
   110  
   111  }