Skip to content

Commit f9dde71

Browse files
authored
Merge pull request #85 from d-ylee/testRaceConditions
Test race conditions in bulkblocks API
2 parents 2aad8db + 6375d6a commit f9dde71

File tree

10 files changed

+353
-7
lines changed

10 files changed

+353
-7
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,11 @@ bench:
178178
DBS_API_PARAMETERS_FILE=../static/parameters.json \
179179
DBS_LEXICON_FILE=../static/lexicon_writer.json \
180180
go test -run Benchmark -bench=.
181+
test-race:
182+
LD_LIBRARY_PATH=${odir} DYLD_LIBRARY_PATH=${odir} \
183+
./bin/start_write_servers && \
184+
cd test && \
185+
LD_LIBRARY_PATH=${odir} DYLD_LIBRARY_PATH=${odir} \
186+
MIGRATION_REQUESTS_PATH=./data/migration/requests \
187+
INTEGRATION_DATA_FILE=./data/integration/integration_data.json \
188+
go test -v -failfast -timeout 10m -run RaceConditions

bin/start_write_servers

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
# Delete original dbfiles and databases and reinitializing them with the schema
4+
rm -f /tmp/dbs-one.db
5+
sqlite3 /tmp/dbs-one.db < ./static/schema/sqlite-schema.sql
6+
echo sqlite3 /tmp/dbs-one.db sqlite > ./test/dbfile_1
7+
8+
# Starting DBS servers
9+
echo Starting dbs-one-writer
10+
./dbs2go -config ./test/config/config_dbs_one_writer2.json &
11+
echo $! >> ./test-pids
12+
13+
sleep 1

dbs/fileparents.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (a *API) FileParents() error {
1717

1818
if len(a.Params) == 0 {
1919
msg := "logical_file_name, block_id or block_name is required for fileparents api"
20-
return Error(InvalidParamErr, ParametersErrorCode, msg, "dbs.fileparents.FielParents")
20+
return Error(InvalidParamErr, ParametersErrorCode, msg, "dbs.fileparents.FileParents")
2121
}
2222

2323
tmpl := make(Record)
@@ -31,7 +31,7 @@ func (a *API) FileParents() error {
3131

3232
stm, err := LoadTemplateSQL("fileparent", tmpl)
3333
if err != nil {
34-
return Error(err, LoadErrorCode, "", "dbs.fileparents.FielParents")
34+
return Error(err, LoadErrorCode, "", "dbs.fileparents.FileParents")
3535
}
3636

3737
lfns := getValues(a.Params, "logical_file_name")
@@ -52,7 +52,7 @@ func (a *API) FileParents() error {
5252
// use generic query API to fetch the results from DB
5353
err = executeAll(a.Writer, a.Separator, stm, args...)
5454
if err != nil {
55-
return Error(err, QueryErrorCode, "", "dbs.fileparents.FielParents")
55+
return Error(err, QueryErrorCode, "", "dbs.fileparents.FileParents")
5656
}
5757
return nil
5858
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"base": "/dbs-one-writer",
3+
"port": 8990,
4+
"staticdir": "./static",
5+
"dbfile": "./test/dbfile_1",
6+
"lexicon_file": "./static/lexicon_writer.json",
7+
"api_parameters_file": "./static/parameters.json",
8+
"server_type": "DBSWriter",
9+
"servercrt": "",
10+
"serverkey": "",
11+
"hkey": "",
12+
"updateDNs": 60,
13+
"log_file": "/tmp/dbs2go_writer_1_2.log",
14+
"verbose": 2,
15+
"limiter_rate": "10000-s",
16+
"concurrent_bulkblocks": true
17+
}

test/int_filearray.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ func getFileArrayTestTable(t *testing.T) []EndpointTestCase {
15531553
output: []Response{errorResp4},
15541554
respCode: http.StatusBadRequest,
15551555
},
1556-
// TODO: Figure out logicl for DBSClientReader_t.test.034l
1556+
// TODO: Figure out logic for DBSClientReader_t.test.034l
15571557
},
15581558
},
15591559
}

test/int_fileparents.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package main
2+
3+
import (
4+
"net/http"
5+
"net/url"
6+
"testing"
7+
8+
"github.com/dmwm/dbs2go/dbs"
9+
"github.com/dmwm/dbs2go/web"
10+
)
11+
12+
func getFileParentsTestTable(t *testing.T) EndpointTestCase {
13+
dbsError := dbs.DBSError{
14+
Reason: dbs.InvalidParamErr.Error(),
15+
Message: "logical_file_name, block_id or block_name is required for fileparents api",
16+
Code: dbs.ParametersErrorCode,
17+
Function: "dbs.fileparents.FileParents",
18+
}
19+
hrec := createHTTPError("GET", "/dbs/primarydstypes?dataset=fnal")
20+
errorResp := web.ServerError{
21+
HTTPError: hrec,
22+
DBSError: &dbsError,
23+
Exception: http.StatusBadRequest,
24+
Type: "HTTPError",
25+
Message: dbsError.Error(),
26+
}
27+
return EndpointTestCase{
28+
description: "Test fileparents",
29+
defaultHandler: web.FileParentsHandler,
30+
defaultEndpoint: "/dbs/fileparents",
31+
testCases: []testCase{
32+
{ // DBSClientReader_t.test041
33+
description: "Test fileparents with lfn",
34+
method: "GET",
35+
serverType: "DBSReader",
36+
params: url.Values{
37+
"logical_file_name": []string{TestData.ParentFiles[0]},
38+
},
39+
output: []Response{},
40+
respCode: http.StatusOK,
41+
},
42+
{ // DBSClientReader_t.test042
43+
description: "Test fileparents with no params",
44+
method: "GET",
45+
serverType: "DBSReader",
46+
params: url.Values{},
47+
output: []Response{errorResp},
48+
respCode: http.StatusBadRequest,
49+
},
50+
},
51+
}
52+
}

test/integration_cases.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ func LoadTestCases(t *testing.T, filepath string, bulkblockspath string, largeBu
567567
bulkBlocksTest := getBulkBlocksTestTable(t)
568568
filesReaderTestTable := getFilesLumiListRangeTestTable(t)
569569
fileArrayTestTable := getFileArrayTestTable(t)
570+
fileParentsTestTable := getFileParentsTestTable(t)
570571
largeFileLumiInsertTestTable := getBulkBlocksLargeFileLumiInsertTestTable(t)
571572
filesReaderAfterChunkTestTable := getFileLumiChunkTestTable(t)
572573

@@ -592,8 +593,15 @@ func LoadTestCases(t *testing.T, filepath string, bulkblockspath string, largeBu
592593
)
593594
endpointTestCases = append(endpointTestCases, filesReaderTestTable...)
594595
endpointTestCases = append(endpointTestCases, fileArrayTestTable...)
595-
endpointTestCases = append(endpointTestCases, largeFileLumiInsertTestTable)
596-
endpointTestCases = append(endpointTestCases, filesReaderAfterChunkTestTable)
596+
597+
endpointTestCases = append(
598+
endpointTestCases,
599+
fileParentsTestTable,
600+
largeFileLumiInsertTestTable,
601+
filesReaderAfterChunkTestTable,
602+
)
603+
// endpointTestCases = append(endpointTestCases, largeFileLumiInsertTestTable)
604+
// endpointTestCases = append(endpointTestCases, filesReaderAfterChunkTestTable)
597605

598606
return endpointTestCases
599607
}

test/migration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ func TestMigrationRequests(t *testing.T) {
677677

678678
bulkblocksPath := os.Getenv("MIGRATION_REQUESTS_PATH")
679679
if bulkblocksPath == "" {
680-
log.Fatal("MIGRATION_REQUESTS_PATH not defined")
680+
t.Fatal("MIGRATION_REQUESTS_PATH not defined")
681681
}
682682

683683
// load grandparent data

0 commit comments

Comments
 (0)