Permalink
Browse files

Change postgresql test database to prepend the cpu string so that run…

…ning two builders on the Mac Pro build machine will not cause random failures due to interference.
  • Loading branch information...
1 parent fcce06f commit 1809b65a9e446c8eaf073f7dd2197ee3ad22fd94 @erg erg committed with erg Sep 4, 2011
View
8 basis/db/errors/errors.factor
@@ -38,6 +38,11 @@ TUPLE: sql-function-missing < sql-error message ;
\ sql-function-missing new
swap >>message ;
+TUPLE: sql-database-exists < sql-error message ;
+: <sql-database-exists> ( message -- error )
+ \ sql-database-exists new
+ swap >>message ;
+
: ignore-error ( quot word -- )
'[ dup _ execute [ drop ] [ rethrow ] if ] recover ; inline
@@ -52,3 +57,6 @@ TUPLE: sql-function-missing < sql-error message ;
: ignore-function-missing ( quot -- )
\ sql-function-missing? ignore-error ; inline
+
+: ignore-database-exists ( quot -- )
+ \ sql-database-exists? ignore-error ; inline
View
6 basis/db/errors/postgresql/postgresql.factor
@@ -15,6 +15,10 @@ TableError =
| Error ("relation "|"table ")(!(" does not exist").)+:table " does not exist"
=> [[ table >string unquote <sql-table-missing> ]]
+DatabaseError =
+ Error ("database")(!(" already exists").)+:database " already exists"
+ => [[ database >string <sql-database-exists> ]]
+
FunctionError =
Error "function" (!(" already exists").)+:table " already exists"
=> [[ table >string <sql-function-exists> ]]
@@ -29,7 +33,7 @@ SyntaxError =
UnknownError = .* => [[ >string <sql-unknown-error> ]]
-PostgresqlSqlError = (TableError | FunctionError | SyntaxError | UnknownError)
+PostgresqlSqlError = (TableError | DatabaseError | FunctionError | SyntaxError | UnknownError)
;EBNF
View
2 basis/db/postgresql/postgresql-tests.factor
@@ -3,7 +3,9 @@ prettyprint sequences namespaces tools.test db db.private
db.tuples db.types unicode.case accessors system db.tester ;
IN: db.postgresql.tests
+
os windows? cpu x86.64? and [
+ ! Ensure the table exists
[ ] [ postgresql-test-db [ ] with-db ] unit-test
[ ] [
View
16 basis/db/queries/queries.factor
@@ -1,10 +1,10 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel math namespaces make sequences random
-strings math.parser math.intervals combinators math.bitwise
-nmake db db.tuples db.types classes words shuffle arrays
-destructors continuations db.tuples.private prettyprint
-db.private byte-arrays ;
+USING: accessors arrays byte-arrays classes combinators
+continuations db db.errors db.private db.tuples
+db.tuples.private db.types destructors kernel make math
+math.bitwise math.intervals math.parser namespaces nmake
+prettyprint random sequences shuffle strings words fry ;
IN: db.queries
GENERIC: where ( specs obj -- )
@@ -208,3 +208,9 @@ M: db-connection <count-statement> ( query -- statement )
: drop-index ( index-name -- )
[ "drop index " % % ] "" make sql-command ;
+
+: create-database ( string -- )
+ "create database " ";" surround sql-command ;
+
+: ensure-database ( string -- )
+ '[ _ create-database ] ignore-database-exists ;
View
20 basis/db/tester/tester.factor
@@ -3,20 +3,30 @@
USING: concurrency.combinators db.pools db.sqlite db.tuples
db.types kernel math random threads tools.test db sequences
io prettyprint db.postgresql accessors io.files.temp
-namespaces fry system math.parser ;
+namespaces fry system math.parser db.queries assocs ;
IN: db.tester
+: postgresql-test-db-name ( -- string )
+ cpu name>> "-" "factor-test" 3append
+ H{ { CHAR: - CHAR: _ } { CHAR: . CHAR: _ } } substitute ;
+
: postgresql-test-db ( -- postgresql-db )
<postgresql-db>
"localhost" >>host
"postgres" >>username
"thepasswordistrust" >>password
- "factor-test" >>database ;
+ postgresql-test-db-name >>database ;
+
+: postgresql-template1-db ( -- postgresql-db )
+ <postgresql-db>
+ "localhost" >>host
+ "postgres" >>username
+ "thepasswordistrust" >>password
+ "template1" >>database ;
: sqlite-test-db ( -- sqlite-db )
"tuples-test.db" temp-file <sqlite-db> ;
-
! These words leak resources, but are useful for interactivel testing
: set-sqlite-db ( -- )
sqlite-db db-open db-connection set ;
@@ -31,6 +41,10 @@ IN: db.tester
] call ; inline
: test-postgresql ( quot -- )
+ postgresql-template1-db [
+ postgresql-test-db-name ensure-database
+ ] with-db
+
'[
os windows? cpu x86.64? and [
[ ] [ postgresql-test-db _ with-db ] unit-test

0 comments on commit 1809b65

Please sign in to comment.