github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/test/devstack/lotus_test.go (about) 1 //go:build integration 2 3 package devstack 4 5 import ( 6 "context" 7 "os" 8 "path/filepath" 9 "strconv" 10 "testing" 11 "time" 12 13 "github.com/filecoin-project/bacalhau/pkg/docker" 14 "github.com/filecoin-project/bacalhau/pkg/job" 15 "github.com/filecoin-project/bacalhau/pkg/logger" 16 "github.com/filecoin-project/bacalhau/pkg/model" 17 "github.com/filecoin-project/bacalhau/pkg/node" 18 "github.com/filecoin-project/bacalhau/pkg/publisher/filecoin_lotus/api" 19 "github.com/filecoin-project/bacalhau/pkg/requester/publicapi" 20 "github.com/filecoin-project/bacalhau/pkg/system" 21 "github.com/filecoin-project/bacalhau/pkg/test/scenario" 22 testutils "github.com/filecoin-project/bacalhau/pkg/test/utils" 23 "github.com/stretchr/testify/assert" 24 "github.com/stretchr/testify/require" 25 "github.com/stretchr/testify/suite" 26 ) 27 28 type lotusNodeSuite struct { 29 suite.Suite 30 } 31 32 func TestLotusNodeSuite(t *testing.T) { 33 suite.Run(t, new(lotusNodeSuite)) 34 } 35 36 func (s *lotusNodeSuite) SetupTest() { 37 docker.MustHaveDocker(s.T()) 38 39 logger.ConfigureTestLogging(s.T()) 40 require.NoError(s.T(), system.InitConfigForTesting(s.T())) 41 } 42 43 func (s *lotusNodeSuite) TestLotusNode() { 44 s.T().Skip("Test is flaky", "https://github.com/filecoin-project/bacalhau/issues/1705", "pkg/publisher/filecoin_lotus/publisher_test.go") 45 testutils.SkipIfArm(s.T(), "https://github.com/filecoin-project/bacalhau/issues/1267") 46 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) 47 defer cancel() 48 49 testCase := scenario.WasmHelloWorld 50 nodeCount := 1 51 52 stack, _ := testutils.SetupTest(ctx, s.T(), nodeCount, 0, true, node.NewComputeConfigWithDefaults(), node.NewRequesterConfigWithDefaults()) 53 54 nodeIDs, err := stack.GetNodeIds() 55 require.NoError(s.T(), err) 56 57 j := &model.Job{} 58 j.APIVersion = model.APIVersionLatest().String() 59 j.Spec = testCase.Spec 60 j.Spec.Verifier = model.VerifierNoop 61 j.Spec.Publisher = model.PublisherFilecoin 62 j.Spec.Outputs = testCase.Outputs 63 j.Spec.Deal = model.Deal{ 64 Concurrency: 1, 65 } 66 67 apiUri := stack.Nodes[0].APIServer.GetURI() 68 apiClient := publicapi.NewRequesterAPIClient(apiUri) 69 submittedJob, err := apiClient.Submit(ctx, j) 70 require.NoError(s.T(), err) 71 72 resolver := apiClient.GetJobStateResolver() 73 resolver.SetWaitTime(10000, time.Millisecond*100) 74 75 err = resolver.Wait( 76 ctx, 77 submittedJob.Metadata.ID, 78 job.WaitExecutionsThrowErrors([]model.ExecutionStateType{ 79 model.ExecutionStateFailed, 80 }), 81 job.WaitForExecutionStates(map[model.ExecutionStateType]int{ 82 model.ExecutionStateCompleted: len(nodeIDs), 83 }), 84 ) 85 require.NoError(s.T(), err) 86 87 shards, err := resolver.GetShards(ctx, submittedJob.Metadata.ID) 88 require.NoError(s.T(), err) 89 90 require.NotNil(s.T(), stack.Lotus) 91 assert.DirExists(s.T(), stack.Lotus.UploadDir) 92 require.DirExists(s.T(), stack.Lotus.PathDir) 93 94 lotus, err := api.NewClientFromConfigDir(ctx, stack.Lotus.PathDir) 95 require.NoError(s.T(), err) 96 s.T().Cleanup(func() { 97 assert.NoError(s.T(), lotus.Close()) 98 }) 99 100 imports, err := lotus.ClientListImports(ctx) 101 require.NoError(s.T(), err) 102 103 require.Len(s.T(), imports, 1) 104 require.Len(s.T(), shards, 1) 105 106 dir := s.T().TempDir() 107 108 require.NoError(s.T(), ExtractCar(ctx, imports[0].FilePath, dir)) 109 110 lotusStdout, err := os.ReadFile(filepath.Join(dir, "stdout")) 111 require.NoError(s.T(), err) 112 lotusStderr, err := os.ReadFile(filepath.Join(dir, "stderr")) 113 require.NoError(s.T(), err) 114 lotusExitCodeStr, err := os.ReadFile(filepath.Join(dir, "exitCode")) 115 require.NoError(s.T(), err) 116 lotusExitCode, err := strconv.Atoi(string(lotusExitCodeStr)) 117 require.NoError(s.T(), err) 118 119 assert.Equal(s.T(), shards[0].RunOutput.STDOUT, string(lotusStdout)) 120 assert.Equal(s.T(), shards[0].RunOutput.STDERR, string(lotusStderr)) 121 assert.Equal(s.T(), shards[0].RunOutput.ExitCode, lotusExitCode) 122 }