github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/test/devstack/jobselection_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 "github.com/filecoin-project/bacalhau/pkg/node" 10 11 "github.com/filecoin-project/bacalhau/pkg/job" 12 _ "github.com/filecoin-project/bacalhau/pkg/logger" 13 "github.com/filecoin-project/bacalhau/pkg/model" 14 "github.com/filecoin-project/bacalhau/pkg/test/scenario" 15 "github.com/stretchr/testify/suite" 16 ) 17 18 type DevstackJobSelectionSuite struct { 19 scenario.ScenarioRunner 20 } 21 22 // In order for 'go test' to run this suite, we need to create 23 // a normal test function and pass our suite to suite.Run 24 func TestDevstackJobSelectionSuite(t *testing.T) { 25 suite.Run(t, new(DevstackJobSelectionSuite)) 26 } 27 28 // Re-use the docker executor tests but full end to end with libp2p transport 29 // and 3 nodes 30 func (suite *DevstackJobSelectionSuite) TestSelectAllJobs() { 31 type TestCase struct { 32 name string 33 policy model.JobSelectionPolicy 34 nodeCount int 35 addFilesCount int 36 expectedAccepts int 37 } 38 39 runTest := func(testCase TestCase) { 40 if testCase.nodeCount != testCase.addFilesCount { 41 suite.T().Skip("https://github.com/filecoin-project/bacalhau/issues/361") 42 } 43 44 testScenario := scenario.Scenario{ 45 Stack: &scenario.StackConfig{ 46 DevStackOptions: &devstack.DevStackOptions{NumberOfHybridNodes: testCase.nodeCount}, 47 ComputeConfig: node.NewComputeConfigWith(node.ComputeConfigParams{ 48 JobSelectionPolicy: testCase.policy, 49 }), 50 }, 51 Inputs: scenario.PartialAdd(testCase.addFilesCount, scenario.WasmCsvTransform.Inputs), 52 Contexts: scenario.WasmCsvTransform.Contexts, 53 Outputs: scenario.WasmCsvTransform.Outputs, 54 Spec: scenario.WasmCsvTransform.Spec, 55 Deal: model.Deal{Concurrency: testCase.nodeCount}, 56 JobCheckers: []job.CheckStatesFunction{ 57 job.WaitDontExceedCount(testCase.expectedAccepts), 58 job.WaitExecutionsThrowErrors([]model.ExecutionStateType{ 59 model.ExecutionStateFailed, 60 }), 61 job.WaitForExecutionStates(map[model.ExecutionStateType]int{ 62 model.ExecutionStateCompleted: testCase.expectedAccepts, 63 }), 64 }, 65 } 66 67 suite.RunScenario(testScenario) 68 } 69 70 for _, testCase := range []TestCase{ 71 72 { 73 name: "all nodes added files, all nodes ran job", 74 policy: model.NewDefaultJobSelectionPolicy(), 75 nodeCount: 3, 76 addFilesCount: 3, 77 expectedAccepts: 3, 78 }, 79 80 // check we get only 2 when we've only added data to 2 81 { 82 name: "only nodes we added data to ran the job", 83 policy: model.NewDefaultJobSelectionPolicy(), 84 nodeCount: 3, 85 addFilesCount: 2, 86 expectedAccepts: 2, 87 }, 88 89 // check we run on all 3 nodes even though we only added data to 1 90 { 91 name: "only added files to 1 node but all 3 run it", 92 policy: model.JobSelectionPolicy{ 93 Locality: model.Anywhere, 94 }, 95 nodeCount: 3, 96 addFilesCount: 1, 97 expectedAccepts: 3, 98 }, 99 } { 100 suite.Run(testCase.name, func() { 101 runTest(testCase) 102 }) 103 } 104 }