Skip to content
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

ADBDEV 6061 Add test for doRestoreAgent in gpbackup #102

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
df8e427
Add simple mocking and test for skip files for doRestoreAgent
dkovalev1 Aug 5, 2024
9106dc8
more clear test definition, add checks for pipes existance
dkovalev1 Aug 14, 2024
8d547f7
Add two more tests to mocking sample
dkovalev1 Aug 20, 2024
a738d7f
Merge branch 'master' into ADBDEV-6061
dkovalev1 Aug 21, 2024
2681013
Fix after merge
dkovalev1 Aug 21, 2024
68b4fcd
implement mocked methods
dkovalev1 Aug 22, 2024
189a078
Change variable case.
dkovalev1 Aug 26, 2024
35e7741
Rename symbols to follow code style
dkovalev1 Aug 27, 2024
381cf2b
Save all global variables on upper level for tests
dkovalev1 Aug 28, 2024
a2ad824
Add recent changes from ADBDEV-6012 and a few more tests
dkovalev1 Sep 4, 2024
aa5d445
Rename interfaces and structs
dkovalev1 Sep 4, 2024
64c5d30
use closeFileHandle instead of getting handle
dkovalev1 Sep 4, 2024
fc23f5a
Add closeAndDeletePipe to the Helper interface
dkovalev1 Sep 4, 2024
7fd9df3
Merge branch 'master' into ADBDEV-6061
dkovalev1 Sep 9, 2024
0171cee
Rename RestoreHelperImpl to RestoreHelper
dkovalev1 Sep 9, 2024
b1fab12
Do not save global variables for test and other cosmetic changes
dkovalev1 Sep 16, 2024
16e5f92
Merge branch 'master' into ADBDEV-6061
dkovalev1 Sep 24, 2024
b34c37f
Add test for plugin error conditions
dkovalev1 Sep 24, 2024
e45e70a
Refactoring suggested by the review
dkovalev1 Oct 2, 2024
247d924
Refactoring inspired by the code review
dkovalev1 Oct 3, 2024
6bba266
Changes according to review
dkovalev1 Oct 10, 2024
eaf99c6
revert some changes to helper.go, make refactroring smaller
dkovalev1 Oct 11, 2024
173fbba
Refactoring inspired by the code review
dkovalev1 Oct 15, 2024
696c2b2
Regactoring for the code review.
dkovalev1 Oct 21, 2024
3586685
Merge branch 'master' into ADBDEV-6061
dkovalev1 Oct 21, 2024
dd8a4da
Move comment into test description, simplify pipes list
dkovalev1 Oct 22, 2024
fb011fa
Use map search for opened pipes, use mocked struct to store preloaded…
dkovalev1 Oct 23, 2024
915c959
Use bool zero value as pipesMap lookup result
dkovalev1 Oct 24, 2024
898f5fa
Make code more readable
dkovalev1 Oct 24, 2024
08edf94
Simplify test after code review
dkovalev1 Oct 24, 2024
53402c7
Changes inspired by code review
dkovalev1 Oct 28, 2024
cae0e76
Fix build
dkovalev1 Oct 28, 2024
ac15111
move closing pipe to increase locality
dkovalev1 Nov 14, 2024
85e8b4f
Merge branch 'master' into ADBDEV-6061
dkovalev1 Nov 29, 2024
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
53 changes: 1 addition & 52 deletions helper/helper.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package helper

import (
"bufio"
"flag"
"fmt"
"os"
Expand All @@ -26,8 +25,6 @@ var (
CleanupGroup *sync.WaitGroup
version string
wasTerminated bool
writeHandle *os.File
writer *bufio.Writer
pipesMap map[string]bool
)

Expand Down Expand Up @@ -205,31 +202,6 @@ func preloadCreatedPipesForBackup(oidList []int, queuedPipeCount int) {
}
}

func preloadCreatedPipesForRestore(oidWithBatchList []oidWithBatch, queuedPipeCount int) {
for i := 0; i < queuedPipeCount; i++ {
pipeName := fmt.Sprintf("%s_%d_%d", *pipeFile, oidWithBatchList[i].oid, oidWithBatchList[i].batch)
pipesMap[pipeName] = true
}
}

func getOidWithBatchListFromFile(oidFileName string) ([]oidWithBatch, error) {
oidStr, err := operating.System.ReadFile(oidFileName)
if err != nil {
logError(fmt.Sprintf("Error encountered reading oid batch list from file: %v", err))
return nil, err
}
oidStrList := strings.Split(strings.TrimSpace(fmt.Sprintf("%s", oidStr)), "\n")
oidList := make([]oidWithBatch, len(oidStrList))
for i, entry := range oidStrList {
oidWithBatchEntry := strings.Split(entry, ",")
oidNum, _ := strconv.Atoi(oidWithBatchEntry[0])
batchNum, _ := strconv.Atoi(oidWithBatchEntry[1])

oidList[i] = oidWithBatch{oid: oidNum, batch: batchNum}
}
return oidList, nil
}

func getOidListFromFile(oidFileName string) ([]int, error) {
oidStr, err := operating.System.ReadFile(oidFileName)
if err != nil {
Expand All @@ -245,29 +217,6 @@ func getOidListFromFile(oidFileName string) ([]int, error) {
return oidList, nil
}

func flushAndCloseRestoreWriter(pipeName string, oid int) error {
whitehawk marked this conversation as resolved.
Show resolved Hide resolved
if writer != nil {
writer.Write([]byte{}) // simulate writer connected in case of error
err := writer.Flush()
if err != nil {
logError("Oid %d: Failed to flush pipe %s", oid, pipeName)
return err
}
writer = nil
logVerbose("Oid %d: Successfully flushed pipe %s", oid, pipeName)
}
if writeHandle != nil {
err := writeHandle.Close()
if err != nil {
logError("Oid %d: Failed to close pipe handle", oid)
return err
}
writeHandle = nil
logVerbose("Oid %d: Successfully closed pipe handle", oid)
}
return nil
}

/*
* Shared helper functions
*/
Expand All @@ -291,7 +240,7 @@ func DoCleanup() {
logVerbose("Encountered error closing error file: %v", err)
}
}
err := flushAndCloseRestoreWriter("Current writer pipe on cleanup", 0)
err := FlushAndCloseRestoreWriter("Current writer pipe on cleanup", 0)
if err != nil {
logVerbose("Encountered error during cleanup: %v", err)
}
Expand Down
Loading
Loading