Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions +dj/conn.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,18 @@


if isa(CONN, 'dj.Connection') && ~reset
assert(nargin==0, ...
'connection already instantiated. To reconnect, clear functions')
if nargin>0
if strcmp(CONN.host,host)
warning('DataJoint:Connection:AlreadyInstantiated', sprintf([...
'Connection already instantiated.\n' ...
'Will use existing connection to "' CONN.host '".\n' ...
'To reconnect, set reset to true']));
else
error('DataJoint:Connection:AlreadyInstantiated', sprintf([...
'Connection already instantiated to "' CONN.host '".\n' ...
'To reconnect, set reset to true']));
end
end
else
% invoke setupDJ
% optional environment variables specifying the connection.
Expand Down
21 changes: 21 additions & 0 deletions +tests/TestConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,26 @@ function testConnection(testCase)
testCase.CONN_INFO.user,...
testCase.CONN_INFO.password,'',true).isConnected);
end
function testConnectionExists(testCase)
% testConnectionExists tests that will not fail if connection open
% to the same host.
% Fix https://github.com/datajoint/datajoint-matlab/issues/160
st = dbstack;
disp(['---------------' st(1).name '---------------']);
dj.conn(testCase.CONN_INFO.host, '', '', '', '', true)
dj.conn(testCase.CONN_INFO.host, '', '', '', '', true)
end
function testConnectionDiffHost(testCase)
% testConnectionDiffHost tests that will fail if connection open
% to a different host.
% Fix https://github.com/datajoint/datajoint-matlab/issues/160
st = dbstack;
disp(['---------------' st(1).name '---------------']);
dj.conn(testCase.CONN_INFO.host, '', '', '', '', true)

testCase.verifyError(@() dj.conn(...
'anything', '', '', '', '', true), ...
'DataJoint:Connection:AlreadyInstantiated');
end
end
end