Skip to content

Commit

Permalink
Fix parallel execution of ChillerElectricASHRAE205 tests by using a u…
Browse files Browse the repository at this point in the history
…nique directory
  • Loading branch information
jmarrec committed Sep 28, 2022
1 parent e19dc8c commit f6af133
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
7 changes: 7 additions & 0 deletions src/energyplus/Test/ChillerElectricASHRAE205_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ TEST_F(EnergyPlusFixture, ForwardTranslator_ChillerElectricASHRAE205) {
openstudio::path p = resourcesPath() / toPath("model/A205ExampleChiller.RS0001.a205.cbor");
EXPECT_TRUE(exists(p));

// Work in a temp dir so we don't mess everything up when running tests in parallel
openstudio::path expectedDestDir = openstudio::tempDir() / openstudio::toPath("ForwardTranslator_ChillerElectricASHRAE205");
if (exists(expectedDestDir)) {
removeDirectory(expectedDestDir);
}
EXPECT_TRUE(m.workflowJSON().addFilePath(expectedDestDir));

boost::optional<ExternalFile> representationFile = ExternalFile::getExternalFile(m, openstudio::toString(p));
ASSERT_TRUE(representationFile);

Expand Down
5 changes: 5 additions & 0 deletions src/model/ExternalFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ namespace model {

try {
makeParentFolder(dest, path(), true);
} catch (std::exception&) {
this->remove();
LOG_AND_THROW("Failed to created parent folder at \"" << dest << "\"");
}
try {
boost::filesystem::copy(p, dest);
} catch (std::exception&) {
this->remove();
Expand Down
45 changes: 13 additions & 32 deletions src/model/test/ChillerElectricASHRAE205_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "../Mixer.hpp"
#include "../Splitter.hpp"

#include "../../utilities/core/Path.hpp"
#include "../../utilities/core/PathHelpers.hpp"
#include <utilities/idd/IddEnums.hxx>
#include <resources.hxx>
Expand All @@ -62,19 +63,12 @@ TEST_F(ModelFixture, ChillerElectricASHRAE205_GettersSetters) {
openstudio::path p = resourcesPath() / toPath("model/A205ExampleChiller.RS0001.a205.cbor");
EXPECT_TRUE(exists(p));

openstudio::path expectedDestDir;
std::vector<openstudio::path> absoluteFilePaths = m.workflowJSON().absoluteFilePaths();
if (absoluteFilePaths.empty()) {
expectedDestDir = m.workflowJSON().absoluteRootDir();
} else {
expectedDestDir = absoluteFilePaths[0];
}

// Work in a temp dir so we don't mess everything up when running tests in parallel
openstudio::path expectedDestDir = openstudio::tempDir() / openstudio::toPath("ChillerElectricASHRAE205_GettersSetters");
if (exists(expectedDestDir)) {
removeDirectory(expectedDestDir);
}
ASSERT_FALSE(exists(expectedDestDir));
EXPECT_TRUE(exists(p));
EXPECT_TRUE(m.workflowJSON().addFilePath(expectedDestDir));

boost::optional<ExternalFile> representationFile = ExternalFile::getExternalFile(m, openstudio::toString(p));
ASSERT_TRUE(representationFile);
Expand Down Expand Up @@ -262,19 +256,12 @@ TEST_F(ModelFixture, ChillerElectricASHRAE205_Loops) {
openstudio::path p = resourcesPath() / toPath("model/A205ExampleChiller.RS0001.a205.cbor");
EXPECT_TRUE(exists(p));

openstudio::path expectedDestDir;
std::vector<openstudio::path> absoluteFilePaths = m.workflowJSON().absoluteFilePaths();
if (absoluteFilePaths.empty()) {
expectedDestDir = m.workflowJSON().absoluteRootDir();
} else {
expectedDestDir = absoluteFilePaths[0];
}

// Work in a temp dir so we don't mess everything up when running tests in parallel
openstudio::path expectedDestDir = openstudio::tempDir() / openstudio::toPath("ChillerElectricASHRAE205_Loops");
if (exists(expectedDestDir)) {
removeDirectory(expectedDestDir);
}
ASSERT_FALSE(exists(expectedDestDir));
EXPECT_TRUE(exists(p));
EXPECT_TRUE(m.workflowJSON().addFilePath(expectedDestDir));

boost::optional<ExternalFile> representationFile = ExternalFile::getExternalFile(m, openstudio::toString(p));
ASSERT_TRUE(representationFile);
Expand Down Expand Up @@ -644,8 +631,8 @@ TEST_F(ModelFixture, ChillerElectricASHRAE205_Loops) {

// Removing the Chiller doesn't remove the ExternalFile
openstudio::path dstPath = representationFile->filePath();
EXPECT_TRUE(exists(p));
EXPECT_TRUE(exists(dstPath));
EXPECT_TRUE(exists(p)) << p;
EXPECT_TRUE(exists(dstPath)) << dstPath;

ch.remove();
EXPECT_EQ(1, m.getConcreteModelObjects<ExternalFile>().size());
Expand Down Expand Up @@ -673,19 +660,13 @@ TEST_F(ModelFixture, ChillerElectricASHRAE205_Clone) {
openstudio::path p = resourcesPath() / toPath("model/A205ExampleChiller.RS0001.a205.cbor");
EXPECT_TRUE(exists(p));

openstudio::path expectedDestDir;
std::vector<openstudio::path> absoluteFilePaths = m.workflowJSON().absoluteFilePaths();
if (absoluteFilePaths.empty()) {
expectedDestDir = m.workflowJSON().absoluteRootDir();
} else {
expectedDestDir = absoluteFilePaths[0];
}

// Work in a temp dir so we don't mess everything up when running tests in parallel
// Work in a temp dir so we don't mess everything up when running tests in parallel
openstudio::path expectedDestDir = openstudio::tempDir() / openstudio::toPath("ChillerElectricASHRAE205_Clone");
if (exists(expectedDestDir)) {
removeDirectory(expectedDestDir);
}
ASSERT_FALSE(exists(expectedDestDir));
EXPECT_TRUE(exists(p));
EXPECT_TRUE(m.workflowJSON().addFilePath(expectedDestDir));

boost::optional<ExternalFile> representationFile = ExternalFile::getExternalFile(m, openstudio::toString(p));
ASSERT_TRUE(representationFile);
Expand Down

0 comments on commit f6af133

Please sign in to comment.