Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 66613fd

Browse files
committed
Reduce code duplication in test/bench/bench.lua
1 parent 6a43ac9 commit 66613fd

File tree

7 files changed

+17
-53
lines changed

7 files changed

+17
-53
lines changed

test/bench/bench.lua

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ local digest = require('digest')
1515
local multirunner = require('test.common.lua.multirunner')
1616
local graphql = require('graphql')
1717
local utils = require('graphql.utils')
18+
local test_utils = require('test.utils')
1819
local test_run = utils.optional_require('test_run')
1920
test_run = test_run and test_run.new()
2021

@@ -29,29 +30,6 @@ local SCRIPT_DIR = fio.abspath(debug.getinfo(1).source:match("@?(.*/)")
2930

3031
local bench = {}
3132

32-
function bench.graphql_from_testdata(testdata, shard)
33-
local accessor_class = shard and graphql.accessor_shard or
34-
graphql.accessor_space
35-
36-
local meta = testdata.get_test_metadata()
37-
38-
local accessor = accessor_class.new({
39-
schemas = meta.schemas,
40-
collections = meta.collections,
41-
service_fields = meta.service_fields,
42-
indexes = meta.indexes,
43-
timeout_ms = graphql.TIMEOUT_INFINITY,
44-
})
45-
46-
local gql_wrapper = graphql.new({
47-
schemas = meta.schemas,
48-
collections = meta.collections,
49-
accessor = accessor,
50-
})
51-
52-
return gql_wrapper
53-
end
54-
5533
local function workload(shard, bench_prepare, bench_iter, opts)
5634
local iterations = opts.iterations
5735
local exp_checksum = opts.checksum
@@ -178,4 +156,14 @@ function bench.run(test_name, opts)
178156
end
179157
end
180158

159+
-- helper for preparing benchmarking environment
160+
function bench.bench_prepare_helper(testdata, shard)
161+
testdata.fill_test_data(shard or box.space)
162+
return test_utils.graphql_from_testdata(testdata, shard, {
163+
graphql_opts = {
164+
timeout_ms = graphql.TIMEOUT_INFINITY,
165+
}
166+
})
167+
end
168+
181169
return bench

test/bench/nesting-1-1.test.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ local testdata = require('test.testdata.bench_testdata')
1616
-- ---------
1717

1818
local function bench_prepare(state)
19-
local virtbox = state.shard or box.space
20-
21-
state.gql_wrapper = bench.graphql_from_testdata(testdata, state.shard)
22-
testdata.fill_test_data(virtbox)
23-
19+
state.gql_wrapper = bench.bench_prepare_helper(testdata, state.shard)
2420
local query = [[
2521
query match_by_user_id($user_id: String) {
2622
user(user_id: $user_id) {

test/bench/nesting-1-100.test.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ local testdata = require('test.testdata.bench_testdata')
1616
-- ---------
1717

1818
local function bench_prepare(state)
19-
local virtbox = state.shard or box.space
20-
21-
state.gql_wrapper = bench.graphql_from_testdata(testdata, state.shard)
22-
testdata.fill_test_data(virtbox)
23-
19+
state.gql_wrapper = bench.bench_prepare_helper(testdata, state.shard)
2420
local query = [[
2521
query match_users {
2622
user {

test/bench/nesting-2-1-1.test.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ local testdata = require('test.testdata.bench_testdata')
1616
-- ---------
1717

1818
local function bench_prepare(state)
19-
local virtbox = state.shard or box.space
20-
21-
state.gql_wrapper = bench.graphql_from_testdata(testdata, state.shard)
22-
testdata.fill_test_data(virtbox)
23-
19+
state.gql_wrapper = bench.bench_prepare_helper(testdata, state.shard)
2420
local query = [[
2521
query match_by_user_and_passport_id($user_id: String,
2622
$passport_id: String) {

test/bench/nesting-2-100-1.test.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ local testdata = require('test.testdata.bench_testdata')
1616
-- ---------
1717

1818
local function bench_prepare(state)
19-
local virtbox = state.shard or box.space
20-
21-
state.gql_wrapper = bench.graphql_from_testdata(testdata, state.shard)
22-
testdata.fill_test_data(virtbox)
23-
19+
state.gql_wrapper = bench.bench_prepare_helper(testdata, state.shard)
2420
local query = [[
2521
query match_by_passport_id($passport_id: String) {
2622
user(user_to_passport_c: {passport_id: $passport_id}) {

test/bench/nesting-3-1-1-1.test.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ local testdata = require('test.testdata.bench_testdata')
1616
-- ---------
1717

1818
local function bench_prepare(state)
19-
local virtbox = state.shard or box.space
20-
21-
state.gql_wrapper = bench.graphql_from_testdata(testdata, state.shard)
22-
testdata.fill_test_data(virtbox)
23-
19+
state.gql_wrapper = bench.bench_prepare_helper(testdata, state.shard)
2420
local query = [[
2521
query match_by_user_and_passport($user_id: String, $number: String) {
2622
user(user_id: $user_id, user_to_passport_c: {

test/bench/nesting-3-100-100-1.test.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ local testdata = require('test.testdata.bench_testdata')
1616
-- ---------
1717

1818
local function bench_prepare(state)
19-
local virtbox = state.shard or box.space
20-
21-
state.gql_wrapper = bench.graphql_from_testdata(testdata, state.shard)
22-
testdata.fill_test_data(virtbox)
23-
19+
state.gql_wrapper = bench.bench_prepare_helper(testdata, state.shard)
2420
local query = [[
2521
query match_by_passport($number: String) {
2622
user(user_to_passport_c: {passport_c: {number: $number}}) {

0 commit comments

Comments
 (0)