Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit ba26ce33
authored
Feb 06, 2015
by
Willyham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add coverage for round robin and force write
1 parent
8cb31290
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
105 additions
and
3 deletions
test/integration/dialects/abstract/connection-manager.test.js
test/integration/dialects/abstract/connection-manager.test.js
View file @
ba26ce3
...
@@ -6,11 +6,18 @@ var chai = require('chai')
...
@@ -6,11 +6,18 @@ var chai = require('chai')
,
sinon
=
require
(
'sinon'
)
,
sinon
=
require
(
'sinon'
)
,
Config
=
require
(
__dirname
+
'/../../../config/config'
)
,
Config
=
require
(
__dirname
+
'/../../../config/config'
)
,
ConnectionManager
=
require
(
__dirname
+
'/../../../../lib/dialects/abstract/connection-manager'
)
,
ConnectionManager
=
require
(
__dirname
+
'/../../../../lib/dialects/abstract/connection-manager'
)
,
Pooling
=
require
(
'generic-pool'
);
,
Pooling
=
require
(
'generic-pool'
)
,
_
=
require
(
'lodash'
)
,
Promise
=
require
(
__dirname
+
'/../../../../lib/promise'
);
chai
.
config
.
includeStack
=
true
;
chai
.
config
.
includeStack
=
true
;
var
baseConf
=
Config
[
Support
.
getTestDialect
()];
var
baseConf
=
Config
[
Support
.
getTestDialect
()];
var
poolEntry
=
{
host
:
baseConf
.
host
,
port
:
baseConf
.
port
,
pool
:
{}
};
describe
(
'Connction Manager'
,
function
()
{
describe
(
'Connction Manager'
,
function
()
{
...
@@ -26,14 +33,109 @@ describe('Connction Manager', function() {
...
@@ -26,14 +33,109 @@ describe('Connction Manager', function() {
it
(
'should initialize a single pool without replication'
,
function
()
{
it
(
'should initialize a single pool without replication'
,
function
()
{
var
options
=
{
var
options
=
{
pool
:
{}
replication
:
null
};
};
var
sequelize
=
Support
.
getSequelizeInstance
(
baseConf
.
database
,
baseConf
.
username
,
baseConf
.
password
,
options
);
var
sequelize
=
Support
.
getSequelizeInstance
(
baseConf
.
database
,
baseConf
.
username
,
baseConf
.
password
,
options
);
var
connectionManager
=
new
ConnectionManager
(
Support
.
getTestDialect
(),
sequelize
);
var
connectionManager
=
new
ConnectionManager
(
Support
.
getTestDialect
(),
sequelize
);
var
poolSpy
=
s
inon
.
spy
(
Pooling
,
"Pool"
);
var
poolSpy
=
s
andbox
.
spy
(
Pooling
,
"Pool"
);
connectionManager
.
initPools
();
connectionManager
.
initPools
();
expect
(
poolSpy
.
calledOnce
).
to
.
be
.
true
;
expect
(
poolSpy
.
calledOnce
).
to
.
be
.
true
;
});
});
it
(
'should initialize a multiple pools with replication'
,
function
()
{
var
options
=
{
replication
:
{
write
:
_
.
clone
(
poolEntry
),
read
:
[
_
.
clone
(
poolEntry
),
_
.
clone
(
poolEntry
)]
}
};
var
sequelize
=
Support
.
getSequelizeInstance
(
baseConf
.
database
,
baseConf
.
username
,
baseConf
.
password
,
options
);
var
connectionManager
=
new
ConnectionManager
(
Support
.
getTestDialect
(),
sequelize
);
var
poolSpy
=
sandbox
.
spy
(
Pooling
,
"Pool"
);
connectionManager
.
initPools
();
expect
(
poolSpy
.
calledTwice
).
to
.
be
.
true
;
});
it
(
'should round robin calls to the read pool'
,
function
()
{
var
slave1
=
_
.
clone
(
poolEntry
);
var
slave2
=
_
.
clone
(
poolEntry
);
slave1
.
host
=
'slave1'
;
slave2
.
host
=
'slave2'
;
var
options
=
{
replication
:
{
write
:
_
.
clone
(
poolEntry
),
read
:
[
slave1
,
slave2
]
}
};
var
sequelize
=
Support
.
getSequelizeInstance
(
baseConf
.
database
,
baseConf
.
username
,
baseConf
.
password
,
options
);
var
connectionManager
=
new
ConnectionManager
(
Support
.
getTestDialect
(),
sequelize
);
var
resolvedPromise
=
new
Promise
(
function
(
resolve
)
{
resolve
({
queryType
:
'read'
});
});
var
connectStub
=
sandbox
.
stub
(
connectionManager
,
'$connect'
).
returns
(
resolvedPromise
);
connectionManager
.
initPools
();
var
queryOptions
=
{
priority
:
0
,
type
:
'SELECT'
,
forceWrite
:
false
};
var
_getConnection
=
_
.
bind
(
connectionManager
.
getConnection
,
connectionManager
,
queryOptions
);
return
_getConnection
()
.
then
(
_getConnection
)
.
then
(
_getConnection
)
.
then
(
function
checkPoolHosts
()
{
chai
.
expect
(
connectStub
.
calledThrice
).
to
.
be
.
true
;
var
calls
=
connectStub
.
getCalls
();
chai
.
expect
(
calls
[
0
].
args
[
0
].
host
).
to
.
eql
(
'slave1'
);
chai
.
expect
(
calls
[
1
].
args
[
0
].
host
).
to
.
eql
(
'slave2'
);
chai
.
expect
(
calls
[
2
].
args
[
0
].
host
).
to
.
eql
(
'slave1'
);
});
});
it
(
'should allow forced reads from the write pool'
,
function
()
{
var
master
=
_
.
clone
(
poolEntry
);
master
.
host
=
'the-boss'
;
var
options
=
{
replication
:
{
write
:
master
,
read
:
[
_
.
clone
(
poolEntry
)]
}
};
var
sequelize
=
Support
.
getSequelizeInstance
(
baseConf
.
database
,
baseConf
.
username
,
baseConf
.
password
,
options
);
var
connectionManager
=
new
ConnectionManager
(
Support
.
getTestDialect
(),
sequelize
);
var
resolvedPromise
=
new
Promise
(
function
(
resolve
)
{
resolve
({
queryType
:
'read'
});
});
var
connectStub
=
sandbox
.
stub
(
connectionManager
,
'$connect'
).
returns
(
resolvedPromise
);
connectionManager
.
initPools
();
var
queryOptions
=
{
priority
:
0
,
type
:
'SELECT'
,
forceWrite
:
true
};
return
connectionManager
.
getConnection
(
queryOptions
)
.
then
(
function
checkPoolHosts
()
{
chai
.
expect
(
connectStub
.
calledOnce
).
to
.
be
.
true
;
var
calls
=
connectStub
.
getCalls
();
chai
.
expect
(
calls
[
0
].
args
[
0
].
host
).
to
.
eql
(
'the-boss'
);
});
});
});
});
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment