-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] Implement redirection without tee and rotation on windows #49906
base: master
Are you sure you want to change the base?
Changes from all commits
dcc508b
10f30e4
893defc
6e11142
1d3f168
b1a9db1
6e1b198
072f52a
d15af0b
896a895
a1f51fc
84d00a8
e20fa51
32130e7
ff64321
b05e10c
6704a45
ee2d500
5a3176d
ad7b292
c51129f
0aea412
c8334ee
6e0bc8b
afaa709
e61b9e2
15c5372
db56818
59cdf29
f1b15c6
b668f3a
80220aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,4 +59,9 @@ std::string JoinPaths(std::string base, const Paths &...components) { | |
(join(base, std::string_view(components)), ...); | ||
return base; | ||
} | ||
|
||
// Read the whole content for the given [fname], and return as string. | ||
// If any error happens, throw exception. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where is exception thrown? |
||
std::string CompleteReadFile(const std::string &fname); | ||
|
||
} // namespace ray |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,8 +12,6 @@ | |||||
// See the License for the specific language governing permissions and | ||||||
// limitations under the License. | ||||||
|
||||||
#if defined(__APPLE__) || defined(__linux__) | ||||||
|
||||||
#include "ray/util/pipe_logger.h" | ||||||
|
||||||
#include <gtest/gtest.h> | ||||||
|
@@ -23,9 +21,13 @@ | |||||
#include <future> | ||||||
#include <string_view> | ||||||
|
||||||
#include "ray/util/tests/unix_test_utils.h" | ||||||
#include "ray/util/filesystem.h" | ||||||
#include "ray/util/util.h" | ||||||
|
||||||
#if defined(__APPLE__) || defined(__linux__) | ||||||
|
||||||
#include <unistd.h> | ||||||
|
||||||
namespace ray { | ||||||
|
||||||
namespace { | ||||||
|
@@ -105,7 +107,29 @@ TEST_P(PipeLoggerTest, PipeWrite) { | |||||
|
||||||
INSTANTIATE_TEST_SUITE_P(PipeLoggerTest, PipeLoggerTest, testing::Values(1024, 3)); | ||||||
|
||||||
// TODO(hjiang): Add more test cases on different combinations. | ||||||
TEST(PipeLoggerTestWithTee, RedirectionWithNoTeeAndRotation) { | ||||||
// TODO(core): We should have a better test util, which allows us to create a temporary | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// testing directory. | ||||||
const std::string test_file_path = absl::StrFormat("%s.out", GenerateUUIDV4()); | ||||||
|
||||||
StreamRedirectionOption logging_option{}; | ||||||
logging_option.file_path = test_file_path; | ||||||
|
||||||
auto log_token = CreateRedirectionFileHandle(logging_option); | ||||||
ASSERT_EQ(write(log_token.GetWriteHandle(), kLogLine1.data(), kLogLine1.length()), | ||||||
kLogLine1.length()); | ||||||
ASSERT_EQ(write(log_token.GetWriteHandle(), kLogLine2.data(), kLogLine2.length()), | ||||||
kLogLine2.length()); | ||||||
log_token.Close(); | ||||||
|
||||||
// Check log content after completion. | ||||||
EXPECT_EQ(CompleteReadFile(test_file_path), | ||||||
absl::StrFormat("%s%s", kLogLine1, kLogLine2)); | ||||||
|
||||||
// Delete temporary file. | ||||||
EXPECT_EQ(unlink(test_file_path.data()), 0); | ||||||
} | ||||||
|
||||||
TEST(PipeLoggerTestWithTee, RedirectionWithTee) { | ||||||
// TODO(core): We should have a better test util, which allows us to create a temporary | ||||||
// testing directory. | ||||||
|
@@ -178,4 +202,35 @@ TEST(PipeLoggerTestWithTee, RotatedRedirectionWithTee) { | |||||
|
||||||
} // namespace ray | ||||||
|
||||||
#elif defined(_WIN32) | ||||||
|
||||||
#include <windows.h> | ||||||
|
||||||
#include "ray/util/tests/windows_test_utils.h" | ||||||
|
||||||
namespace ray { | ||||||
|
||||||
TEST(PipeLoggerTestWithTee, RedirectionWithNoTeeAndRotation) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need to write the same test twice? I think you can write one that's runnable in both linux and windows |
||||||
const std::string test_file_path = absl::StrFormat("%s.out", GenerateUUIDV4()); | ||||||
|
||||||
StreamRedirectionOption logging_option{}; | ||||||
logging_option.file_path = test_file_path; | ||||||
|
||||||
auto log_token = CreateRedirectionFileHandle(logging_option); | ||||||
ASSERT_EQ(write(log_token.GetWriteHandle(), kLogLine1.data(), kLogLine1.length()), | ||||||
kLogLine1.length()); | ||||||
ASSERT_EQ(write(log_token.GetWriteHandle(), kLogLine2.data(), kLogLine2.length()), | ||||||
kLogLine2.length()); | ||||||
log_token.Close(); | ||||||
|
||||||
// Check log content after completion. | ||||||
EXPECT_EQ(CompleteReadFile(test_file_path), | ||||||
absl::StrFormat("%s%s", kLogLine1, kLogLine2)); | ||||||
|
||||||
// Delete temporary file. | ||||||
EXPECT_EQ(DeleteFile(test_file_path.c_str()), TRUE); | ||||||
} | ||||||
|
||||||
} // namespace ray | ||||||
|
||||||
#endif |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reading, the file should be in the eof state which is not good()?