-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changelog entry: * Tell the server more about the connecting client: hostname, application name, pymonetdb version, process id and an optional remark. This information will show up in the `sys.sessions` table. Configurable with the new settings `client_info`, `client_application` and `client_remark`.
- Loading branch information
1 parent
a4cabfb
commit abfd659
Showing
5 changed files
with
140 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V. | ||
|
||
from unittest import TestCase, skipUnless | ||
import pymonetdb | ||
|
||
from tests.util import have_monetdb_version_at_least, test_url | ||
|
||
QUERY = """\ | ||
SELECT language, peer, hostname, application, client, clientpid, remark | ||
FROM sys.sessions | ||
WHERE sessionid = sys.current_sessionid() | ||
""" | ||
|
||
SERVER_HAS_CLIENTINFO = have_monetdb_version_at_least(11, 51, 0) | ||
|
||
|
||
@skipUnless(SERVER_HAS_CLIENTINFO, "server does not support clientinfo") | ||
class TestClientInfo(TestCase): | ||
|
||
def get_clientinfo(self, **connect_args): | ||
with pymonetdb.connect(test_url, **connect_args) as conn, conn.cursor() as c: | ||
nrows = c.execute(QUERY) | ||
self.assertEqual(nrows, 1) | ||
row = c.fetchone() | ||
d = dict( | ||
(descr.name, v) for descr, v in zip(c.description, row) | ||
) | ||
return d | ||
|
||
# 'application': 'python3 -m unittest' | ||
# 'client': 'pymonetdb 1.8.2a0' | ||
# 'clientpid': 2762097 | ||
# 'hostname': 'totoro' | ||
# 'language': 'sql' | ||
# 'peer': '<UNIX SOCKET>' | ||
# 'remark': None | ||
|
||
def test_default_clientinfo(self): | ||
d = self.get_clientinfo() | ||
self.assertEqual(d['language'], 'sql') | ||
self.assertIsNotNone(d['peer']) | ||
self.assertIsNotNone(d['hostname']) | ||
self.assertIsNotNone(d['application']) | ||
self.assertIn('pymonetdb', d['client']) | ||
self.assertIn(pymonetdb.__version__, d['client']) | ||
self.assertGreater(d['clientpid'], 0) | ||
self.assertIsNone(d['remark']) | ||
|
||
def test_suppressed_clientinfo(self): | ||
d = self.get_clientinfo(client_info=False) | ||
self.assertEqual(d['language'], 'sql') | ||
self.assertIsNotNone(d['peer']) | ||
self.assertIsNone(d['hostname']) | ||
self.assertIsNone(d['application']) | ||
self.assertIsNone(d['client']) | ||
self.assertIsNone(d['clientpid']) | ||
self.assertIsNone(d['remark']) | ||
|
||
def test_set_application_name(self): | ||
d = self.get_clientinfo(client_application='banana') | ||
self.assertEqual(d['application'], 'banana') | ||
d = self.get_clientinfo(client_info=False, client_application='banana') | ||
self.assertIsNone(d['application']) | ||
|
||
def test_set_remark(self): | ||
d = self.get_clientinfo(client_remark='banana') | ||
self.assertEqual(d['remark'], 'banana') | ||
d = self.get_clientinfo(client_info=False, client_remark='banana') | ||
self.assertIsNone(d['remark']) |