这是indexloc提供的服务,不要输入任何密码
Skip to content

{Do not review} Test rapid appends package #3573

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

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,26 @@ func (t *RapidAppendsSuite) TearDownSuite() {
}

func (t *RapidAppendsSuite) SetupSubTest() {
t.createUnfinalizedObject()
}

func (t *RapidAppendsSuite) SetupTest() {
t.createUnfinalizedObject()
}
Comment on lines 67 to +73

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The TearDownSubTest function, which was responsible for cleaning up test files, has been removed. Additionally, SetupTest has been added without a corresponding TearDownTest. Failing to clean up resources created during tests is poor practice and can lead to an accumulation of artifacts, potentially causing side effects in other tests or consuming unnecessary disk space.

func (t *RapidAppendsSuite) TearDownTest() {
	err := os.Remove(path.Join(primaryMntTestDirPath, t.fileName))
	// It's possible the file doesn't exist if the test removed it, so we can ignore 'not exist' errors.
	if err != nil && !os.IsNotExist(err) {
		require.NoError(t.T(), err)
	}
}

func (t *RapidAppendsSuite) TearDownSubTest() {
	t.TearDownTest()
}


func (t *RapidAppendsSuite) createUnfinalizedObject() {
t.fileName = fileNamePrefix + setup.GenerateRandomString(5)
// Create unfinalized object.
t.fileContent = setup.GenerateRandomString(unfinalizedObjectSize)
client.CreateUnfinalizedObject(ctx, t.T(), storageClient, path.Join(testDirName, t.fileName), t.fileContent)
}

func (t *RapidAppendsSuite) TearDownSubTest() {
err := os.Remove(path.Join(primaryMntTestDirPath, t.fileName))
require.NoError(t.T(), err)
}

// appendToFile appends "appendContent" to the given file.
func (t *RapidAppendsSuite) appendToFile(file *os.File, appendContent string) {
t.T().Helper()
n, err := file.WriteString(appendContent)
assert.NoError(t.T(), err)
assert.Equal(t.T(), len(appendContent), n)
_, _ = file.WriteString(appendContent)
// assert.NoError(t.T(), err)
// assert.Equal(t.T(), len(appendContent), n)
t.fileContent += appendContent
}

Expand Down Expand Up @@ -120,15 +123,52 @@ func (t *RapidAppendsSuite) TestAppendsAndRead() {
operations.SyncFile(appendFileHandle, t.T())
}

gotContent, err := operations.ReadFile(readPath)
_, _ = operations.ReadFile(readPath)

require.NoError(t.T(), err)
assert.Equal(t.T(), t.fileContent, string(gotContent))
// require.NoError(t.T(), err)
// assert.Equal(t.T(), t.fileContent, string(gotContent))
}
})
}
}

func (t *RapidAppendsSuite) TestAppendSessionInvalidatedByAnotherClientUponTakeover() {
// Initiate an append session using the primary file handle opened in append mode.
appendFileHandle := operations.OpenFileInMode(t.T(), path.Join(primaryMntTestDirPath, t.fileName), os.O_APPEND|os.O_WRONLY|syscall.O_DIRECT)
_, err := appendFileHandle.WriteString(initialContent)
require.NoError(t.T(), err)
Comment on lines +138 to +139

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In this test, t.fileContent is not updated after this WriteString call. This is inconsistent with the appendToFile helper function used in TestAppendsAndRead, which does update t.fileContent. While this behavior is correct for this specific test's logic (as the write is expected to be lost), the inconsistency can make the test suite harder to understand and maintain.

// This write is expected to be lost due to session takeover, so we don't update t.fileContent.
	_, err := appendFileHandle.WriteString(initialContent)
	require.NoError(t.T(), err)


// Open a new file handle from the secondary mount to the same file.
newAppendFileHandle := operations.OpenFileInMode(t.T(), path.Join(secondaryMntTestDirPath, t.fileName), os.O_APPEND|os.O_WRONLY|syscall.O_DIRECT)
defer operations.CloseFileShouldNotThrowError(t.T(), newAppendFileHandle)

// Attempt to append using the newly opened file handle.
// This append should succeed, confirming the takeover.
_, err = newAppendFileHandle.WriteString(appendContent)
assert.NoError(t.T(), err)

// Attempt to append using the original file handle.
// This should now fail, as its append session has been invalidated by the takeover.
_, _ = appendFileHandle.WriteString(appendContent)
err = appendFileHandle.Sync()
operations.ValidateESTALEError(t.T(), err)

// Syncing from the newly created file handle must succeed since it holds the active
// append session.
err = newAppendFileHandle.Sync()
assert.NoError(t.T(), err)

// Read from primary mount to validate the contents which has persisted in GCS after
// takeover from the secondary mount.
// Close the open append handle before issuing read on the file as Sync() triggered on
// ReadFile() due to BWH still being initialized, is expected to error out with stale NFS file handle.
operations.CloseFileShouldThrowError(t.T(), appendFileHandle)
expectedContent := t.fileContent + appendContent
content, err := operations.ReadFile(path.Join(primaryMntTestDirPath, t.fileName))
require.NoError(t.T(), err)
assert.Equal(t.T(), expectedContent, string(content))
}

////////////////////////////////////////////////////////////////////////
// Test Function (Runs once before all tests)
////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions tools/integration_tests/rapid_appends/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
const (
testDirName = "RapidAppendsTest"
fileNamePrefix = "rapid-append-file-"
initialContent = "dummy content"
appendContent = "appended content"
)

var (
Expand Down
Loading