-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34390 from ClickHouse/backport/21.12/34327
Backport #34327 to 21.12: Try to fix rare bug in reading of empty arrays
- Loading branch information
Showing
4 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <gtest/gtest.h> | ||
#include <Common/filesystemHelpers.h> | ||
#include <IO/WriteBufferFromFile.h> | ||
#include <IO/ReadBufferFromFile.h> | ||
#include <IO/WriteHelpers.h> | ||
#include <IO/ReadHelpers.h> | ||
|
||
using namespace DB; | ||
|
||
TEST(ReadBufferFromFile, seekBackwards) | ||
{ | ||
static constexpr size_t N = 256; | ||
static constexpr size_t BUF_SIZE = 64; | ||
|
||
auto tmp_file = createTemporaryFile("/tmp/"); | ||
|
||
{ | ||
WriteBufferFromFile out(tmp_file->path()); | ||
for (size_t i = 0; i < N; ++i) | ||
writeIntBinary(i, out); | ||
} | ||
|
||
ReadBufferFromFile in(tmp_file->path(), BUF_SIZE); | ||
size_t x; | ||
|
||
/// Read something to initialize the buffer. | ||
in.seek(BUF_SIZE * 10, SEEK_SET); | ||
readIntBinary(x, in); | ||
|
||
/// Check 2 consecutive seek calls without reading. | ||
in.seek(BUF_SIZE * 2, SEEK_SET); | ||
in.seek(BUF_SIZE, SEEK_SET); | ||
|
||
readIntBinary(x, in); | ||
ASSERT_EQ(x, 8); | ||
} |