|
| 1 | +//go:build !go_tarantool_call_17 |
| 2 | +// +build !go_tarantool_call_17 |
| 3 | + |
| 4 | +package connection_pool_test |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/stretchr/testify/require" |
| 10 | + "github.com/tarantool/go-tarantool/connection_pool" |
| 11 | + "github.com/tarantool/go-tarantool/test_helpers" |
| 12 | +) |
| 13 | + |
| 14 | +func TestCall(t *testing.T) { |
| 15 | + roles := []bool{false, true, false, false, true} |
| 16 | + |
| 17 | + err := test_helpers.SetClusterRO(servers, connOpts, roles) |
| 18 | + require.Nilf(t, err, "fail to set roles for cluster") |
| 19 | + |
| 20 | + connPool, err := connection_pool.Connect(servers, connOpts) |
| 21 | + require.Nilf(t, err, "failed to connect") |
| 22 | + require.NotNilf(t, connPool, "conn is nil after Connect") |
| 23 | + |
| 24 | + defer connPool.Close() |
| 25 | + |
| 26 | + // PreferRO |
| 27 | + resp, err := connPool.Call("box.info", []interface{}{}, connection_pool.PreferRO) |
| 28 | + require.Nilf(t, err, "failed to Call") |
| 29 | + require.NotNilf(t, resp, "response is nil after Call") |
| 30 | + require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") |
| 31 | + |
| 32 | + val := resp.Data[0].([]interface{})[0].(map[interface{}]interface{})["ro"] |
| 33 | + ro, ok := val.(bool) |
| 34 | + require.Truef(t, ok, "expected `true` with mode `PreferRO`") |
| 35 | + require.Truef(t, ro, "expected `true` with mode `PreferRO`") |
| 36 | + |
| 37 | + // PreferRW |
| 38 | + resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.PreferRW) |
| 39 | + require.Nilf(t, err, "failed to Call") |
| 40 | + require.NotNilf(t, resp, "response is nil after Call") |
| 41 | + require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") |
| 42 | + |
| 43 | + val = resp.Data[0].([]interface{})[0].(map[interface{}]interface{})["ro"] |
| 44 | + ro, ok = val.(bool) |
| 45 | + require.Truef(t, ok, "expected `false` with mode `PreferRW`") |
| 46 | + require.Falsef(t, ro, "expected `false` with mode `PreferRW`") |
| 47 | + |
| 48 | + // RO |
| 49 | + resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.RO) |
| 50 | + require.Nilf(t, err, "failed to Call") |
| 51 | + require.NotNilf(t, resp, "response is nil after Call") |
| 52 | + require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") |
| 53 | + |
| 54 | + val = resp.Data[0].([]interface{})[0].(map[interface{}]interface{})["ro"] |
| 55 | + ro, ok = val.(bool) |
| 56 | + require.Truef(t, ok, "expected `true` with mode `RO`") |
| 57 | + require.Truef(t, ro, "expected `true` with mode `RO`") |
| 58 | + |
| 59 | + // RW |
| 60 | + resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.RW) |
| 61 | + require.Nilf(t, err, "failed to Call") |
| 62 | + require.NotNilf(t, resp, "response is nil after Call") |
| 63 | + require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") |
| 64 | + |
| 65 | + val = resp.Data[0].([]interface{})[0].(map[interface{}]interface{})["ro"] |
| 66 | + ro, ok = val.(bool) |
| 67 | + require.Truef(t, ok, "expected `false` with mode `RW`") |
| 68 | + require.Falsef(t, ro, "expected `false` with mode `RW`") |
| 69 | +} |
0 commit comments