diff --git a/functionsystem/src/function_agent/code_deployer/working_dir_deployer.cpp b/functionsystem/src/function_agent/code_deployer/working_dir_deployer.cpp index bec934f5f11acd62bde78a9c1423d8d7f6b05177..5e2180ef856ab950c2d418673f2025c3f621144a 100644 --- a/functionsystem/src/function_agent/code_deployer/working_dir_deployer.cpp +++ b/functionsystem/src/function_agent/code_deployer/working_dir_deployer.cpp @@ -98,7 +98,7 @@ std::string WorkingDirDeployer::GetDestination( } if (!IsFile(accessor->GetResource()) && uriFile.find(FILE_SCHEME) == std::string::npos - && litebus::os::Mkdir(uriFile).IsSome()) { + && litebus::os::Mkdir(uriFile).IsNone()) { YRLOG_DEBUG("{}|delegate working dir is a non-exist path, mkdir and use it as destination: {}", appID, uriFile); return uriFile; } diff --git a/functionsystem/tests/unit/function_agent/agent_service/agent_service_actor_test.cpp b/functionsystem/tests/unit/function_agent/agent_service/agent_service_actor_test.cpp index 036a58a1c3f82c2a42caf61768f42bfa742edc99..3ba8a263d2c6de6e2c09e8bf894b93358ccfadca 100644 --- a/functionsystem/tests/unit/function_agent/agent_service/agent_service_actor_test.cpp +++ b/functionsystem/tests/unit/function_agent/agent_service/agent_service_actor_test.cpp @@ -2965,6 +2965,56 @@ TEST_F(DISABLED_AgentServiceActorTest, DeployInstanceWithWorkingDirCpp) DestroyWorkingDir("/tmp/working_dir-tmp"); } +TEST_F(DISABLED_AgentServiceActorTest, DeployInstanceWithNonExistWorkingDirCpp) +{ + PrepareWorkingDir("/tmp/working_dir-tmp"); + auto deployInstanceReq = std::make_unique(); + deployInstanceReq->set_requestid(TEST_REQUEST_ID); // as appID + deployInstanceReq->set_instanceid(TEST_INSTANCE_ID); + deployInstanceReq->set_language("cpp11"); + + auto spec = deployInstanceReq->mutable_funcdeployspec(); + spec->set_storagetype(function_agent::WORKING_DIR_STORAGE_TYPE); + auto deployDir = "/tmp/home/sn/function/package/xxxz"; + + std::string destination = "/tmp/working_dir-tmp-fake/"; + (void)litebus::os::Rmdir(deployDir); + (void)litebus::os::Rmdir(destination); + EXPECT_FALSE(litebus::os::ExistPath(destination)); + spec->set_deploydir(deployDir); + + // path + deployInstanceReq->mutable_createoptions()->insert( + { "DELEGATE_DOWNLOAD", + R"({"appId":"userWorkingDirCode001", "storage_type":"working_dir", "code_path":"/tmp/working_dir-tmp-fake/"})" }); + messages::StartInstanceResponse startInstanceResponse; + startInstanceResponse.set_code(StatusCode::SUCCESS); + startInstanceResponse.set_requestid(TEST_REQUEST_ID); + startInstanceResponse.mutable_startruntimeinstanceresponse()->set_runtimeid(TEST_RUNTIME_ID); + EXPECT_CALL(*testRuntimeManager_, MockStartInstanceResponse) + .WillOnce(Return(startInstanceResponse.SerializeAsString())); + + testFuncAgentMgrActor_->ResetDeployInstanceResponse(); + testFuncAgentMgrActor_->SendRequestToAgentServiceActor(dstActor_->GetAID(), + "DeployInstance", + std::move(deployInstanceReq->SerializeAsString())); + ASSERT_AWAIT_TRUE( + [&]() -> bool { return testFuncAgentMgrActor_->GetDeployInstanceResponse()->requestid() == TEST_REQUEST_ID; }); + EXPECT_TRUE(litebus::os::ExistPath(destination)); // app deployed + + auto startInstanceRequest = std::make_shared(); + startInstanceRequest->ParseFromString(testRuntimeManager_->promiseOfStartInstanceRequest.GetFuture().Get()); + YRLOG_DEBUG(startInstanceRequest->ShortDebugString()); + EXPECT_EQ( + startInstanceRequest->runtimeinstanceinfo().runtimeconfig().posixenvs().find(UNZIPPED_WORKING_DIR)->second, + destination); // startInstance param posixenvs should contain UNZIPPED_WORKING_DIR + EXPECT_EQ(startInstanceRequest->runtimeinstanceinfo().runtimeconfig().posixenvs().find(YR_WORKING_DIR)->second, + destination); // startInstance param posixenvs should contain YR_WORKING_DIR + EXPECT_TRUE(litebus::os::ExistPath(destination)); + DestroyWorkingDir("/tmp/working_dir-tmp"); + (void)litebus::os::Rmdir(destination); +} + TEST_F(DISABLED_AgentServiceActorTest, SendS3Alarm) { metrics::MetricsAdapter::GetInstance().enabledInstruments_.insert(metrics::YRInstrument::YR_S3_ALARM);