~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to database/schema/testfuncs.sql

  • Committer: Curtis Hovey
  • Date: 2011-08-21 14:21:06 UTC
  • mto: This revision was merged to the branch mainline in revision 13745.
  • Revision ID: curtis.hovey@canonical.com-20110821142106-x93hajd6iguma8gx
Update test that was enforcing bad grammar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 2009 Canonical Ltd.  This software is licensed under the
 
3
GNU Affero General Public License version 3 (see the file LICENSE).
 
4
 
 
5
Stored procedures designed for use only by the test suite. These
 
6
will not be loaded onto the production database
 
7
*/
 
8
 
 
9
CREATE OR REPLACE FUNCTION _killall_backends(text)
 
10
RETURNS Boolean AS $$
 
11
    import os
 
12
    from signal import SIGTERM
 
13
 
 
14
    plan = plpy.prepare(
 
15
        "SELECT procpid FROM pg_stat_activity WHERE datname=$1", ['text']
 
16
        )
 
17
    success = True
 
18
    for row in plpy.execute(plan, args):
 
19
        try:
 
20
            plpy.info("Killing %d" % row['procpid'])
 
21
            os.kill(row['procpid'], SIGTERM)
 
22
        except OSError:
 
23
            success = False
 
24
 
 
25
    return success
 
26
$$ LANGUAGE plpythonu;
 
27
 
 
28
COMMENT ON FUNCTION _killall_backends(text) IS 'Kill all backend processes connected to the given database. Note that this is unlikely to work if you are connected to the database you are killing, as you are likely to kill your own connection before all the others have been killed.';
 
29