Skip to content

Commit

Permalink
Add new integration test to test injection of the same block
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Nov 21, 2022
1 parent 4b8fa39 commit bc37f62
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
37 changes: 37 additions & 0 deletions test/int_bulkblocks.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package main

import (
"fmt"
"net/http"
"net/url"
"testing"

"github.com/dmwm/dbs2go/dbs"
"github.com/dmwm/dbs2go/web"
)

Expand Down Expand Up @@ -106,3 +108,38 @@ func getBulkBlocksLargeFileLumiInsertTestTable(t *testing.T) EndpointTestCase {
},
}
}

// test that we will get DBSError when use the same block with bulkblocks API
func bulkblocksTheSameBlockInsertTestTable(t *testing.T) EndpointTestCase {
// there are multiple blocks to insert, but everything is started from parent blocks
bName := TestData.ParentStepchainBlock
reason := fmt.Sprintf("Block %s already exists", bName)
msg := "Data already exist in DBS"
dbsError := dbs.DBSError{
Function: "dbs.bulkblocks.checkBlockExist",
Code: dbs.BlockAlreadyExists,
Reason: reason,
Message: msg,
}
hrec := createHTTPError("POST", "/dbs/bulkblocks")
errorResp := createServerErrorResponse(hrec, &dbsError)
return EndpointTestCase{
description: "Test concurrent bulkblocks with the same block name twice",
defaultHandler: web.BulkBlocksHandler,
defaultEndpoint: "/dbs/bulkblocks",
testCases: []testCase{
{
description: "Test POST with the same block",
serverType: "DBSWriter",
method: "POST",
concurrentBulkBlocks: true,
input: BulkBlocksData.ConcurrentParentData,
output: []Response{
errorResp,
},
handler: web.BulkBlocksHandler,
respCode: http.StatusBadRequest,
},
},
}
}
2 changes: 2 additions & 0 deletions test/integration_cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ func LoadTestCases(t *testing.T, filepath string, bulkblockspath string, largeBu
fileParentsTestTable := getFileParentsTestTable(t)
largeFileLumiInsertTestTable := getBulkBlocksLargeFileLumiInsertTestTable(t)
filesReaderAfterChunkTestTable := getFileLumiChunkTestTable(t)
theSameBlockWithBulkblocks := bulkblocksTheSameBlockInsertTestTable(t)

endpointTestCases = append(
endpointTestCases,
Expand Down Expand Up @@ -599,6 +600,7 @@ func LoadTestCases(t *testing.T, filepath string, bulkblockspath string, largeBu
fileParentsTestTable,
largeFileLumiInsertTestTable,
filesReaderAfterChunkTestTable,
theSameBlockWithBulkblocks,
)
// endpointTestCases = append(endpointTestCases, largeFileLumiInsertTestTable)
// endpointTestCases = append(endpointTestCases, filesReaderAfterChunkTestTable)
Expand Down
6 changes: 5 additions & 1 deletion test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ func runTestWorkflow(t *testing.T, c EndpointTestCase) {
var d []dbs.Record
// decode and verify the GET request
// Also handles fileArray using POST to fetch data
if v.method == "GET" || (v.method == "POST" && strings.Contains(endpoint, "fileArray")) {
if v.method == "GET" || (v.method == "POST" && strings.Contains(endpoint, "fileArray")) || (v.method == "POST" && strings.Contains(endpoint, "bulkblocks")) {
// if v.method == "GET" || (v.method == "POST" && strings.Contains(endpoint, "fileArray")) {
err = json.NewDecoder(r.Body).Decode(&d)
if err != nil {
t.Fatalf("Failed to decode body, %v", err)
Expand All @@ -108,6 +109,9 @@ func runTestWorkflow(t *testing.T, c EndpointTestCase) {
} else if v.method == "POST" {
rURL := parseURL(t, server.URL, endpoint, v.params)
rr, err := respRecorder("GET", rURL.RequestURI(), nil, handler)
// VK: why we use respRecorder with GET method here?
// I would expect something like:
// rr, err := respRecorder("POST", endpoint, reader, handler)
if err != nil {
t.Error(err)
}
Expand Down

0 comments on commit bc37f62

Please sign in to comment.