github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/test/executor/test_runner.go (about) 1 package executor 2 3 import ( 4 "context" 5 "testing" 6 "time" 7 8 _ "github.com/filecoin-project/bacalhau/pkg/logger" 9 "github.com/filecoin-project/bacalhau/pkg/model" 10 "github.com/filecoin-project/bacalhau/pkg/node" 11 "github.com/filecoin-project/bacalhau/pkg/test/scenario" 12 testutils "github.com/filecoin-project/bacalhau/pkg/test/utils" 13 "github.com/stretchr/testify/require" 14 ) 15 16 const testNodeCount = 1 17 18 func RunTestCase( 19 t *testing.T, 20 testCase scenario.Scenario, 21 ) { 22 ctx := context.Background() 23 spec := testCase.Spec 24 25 stack, _ := testutils.SetupTest(ctx, t, testNodeCount, 0, false, 26 node.NewComputeConfigWithDefaults(), 27 node.NewRequesterConfigWithDefaults(), 28 ) 29 executor, err := stack.Nodes[0].ComputeNode.Executors.Get(ctx, spec.Engine) 30 require.NoError(t, err) 31 32 isInstalled, err := executor.IsInstalled(ctx) 33 require.NoError(t, err) 34 require.True(t, isInstalled) 35 36 prepareStorage := func(getStorage scenario.SetupStorage) []model.StorageSpec { 37 if getStorage == nil { 38 return []model.StorageSpec{} 39 } 40 41 storageList, stErr := getStorage(ctx, 42 model.StorageSourceIPFS, stack.IPFSClients()[:testNodeCount]...) 43 require.NoError(t, stErr) 44 45 for _, storageSpec := range storageList { 46 hasStorage, stErr := executor.HasStorageLocally( 47 ctx, storageSpec) 48 require.NoError(t, stErr) 49 require.True(t, hasStorage) 50 } 51 52 return storageList 53 } 54 55 spec.Inputs = prepareStorage(testCase.Inputs) 56 spec.Contexts = prepareStorage(testCase.Contexts) 57 spec.Outputs = testCase.Outputs 58 spec.Deal = model.Deal{Concurrency: testNodeCount} 59 60 job := &model.Job{ 61 Metadata: model.Metadata{ 62 ID: "test-job", 63 ClientID: "test-client", 64 CreatedAt: time.Now(), 65 Requester: model.JobRequester{ 66 RequesterNodeID: "test-owner", 67 }, 68 }, 69 Spec: spec, 70 } 71 72 shard := model.JobShard{ 73 Job: job, 74 Index: 0, 75 } 76 77 resultsDirectory := t.TempDir() 78 79 runnerOutput, err := executor.RunShard(ctx, shard, resultsDirectory) 80 require.NoError(t, err) 81 require.Empty(t, runnerOutput.ErrorMsg) 82 83 err = testCase.ResultsChecker(resultsDirectory) 84 require.NoError(t, err) 85 }