summaryrefslogtreecommitdiff
path: root/tests/test9.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test9.cpp')
-rw-r--r--tests/test9.cpp38
1 files changed, 24 insertions, 14 deletions
diff --git a/tests/test9.cpp b/tests/test9.cpp
index cf61508..5252524 100644
--- a/tests/test9.cpp
+++ b/tests/test9.cpp
@@ -33,8 +33,8 @@
using namespace sqlite3xx;
using namespace std;
-const int NOF_PRODUCERS = 1;
-const int NOF_CONSUMERS = 1;
+const int NOF_PRODUCERS = 10;
+const int NOF_CONSUMERS = 10;
const int NOF_PRODUCER_TRANSACTIONS = 100;
const int NOF_PRODUCER_OPS = 100;
const int NOF_CONSUMER_TRANSACTIONS = 100;
@@ -64,8 +64,13 @@ static THREAD_FUNC_DECL produce( void *thread_data )
MUTEX_UNLOCK( cout_mutex );
}
for( int j = 0; j < NOF_PRODUCER_OPS; j++ ) {
- result r = t.prepared( "ins" )( no * 100000 + i * 1000 + j ).exec( );
- assert( r.affected_rows( ) == 1 );
+PRODUCER_INS_AGAIN:
+ try {
+ result r = t.prepared( "ins" )( no * 100000 + i * 1000 + j ).exec( );
+ assert( r.affected_rows( ) == 1 );
+ } catch( database_locked& e ) {
+ goto PRODUCER_INS_AGAIN;
+ }
}
t.commit( );
if( verbose ) {
@@ -98,16 +103,21 @@ static THREAD_FUNC_DECL consume( void *thread_data )
MUTEX_UNLOCK( cout_mutex );
}
for( int j = 0; j < NOF_CONSUMER_OPS; j++ ) {
- result r = t.prepared( "sel" ).exec( );
- int nof_rows = 1;
- for( result::const_iterator it = r.begin( ); it < r.end( ); it++, nof_rows++ ) {
- int x;
- it["x"].to( x );
- }
- if( verbose ) {
- MUTEX_LOCK( cout_mutex );
- cout << "consumer " << no << " transaction " << i << " got " << nof_rows << " rows." << endl;
- MUTEX_UNLOCK( cout_mutex );
+CONSUMER_SELECT_AGAIN:
+ try {
+ result r = t.prepared( "sel" ).exec( );
+ int nof_rows = 1;
+ for( result::const_iterator it = r.begin( ); it < r.end( ); it++, nof_rows++ ) {
+ int x;
+ it["x"].to( x );
+ }
+ if( verbose ) {
+ MUTEX_LOCK( cout_mutex );
+ cout << "consumer " << no << " transaction " << i << " got " << nof_rows << " rows." << endl;
+ MUTEX_UNLOCK( cout_mutex );
+ }
+ } catch( database_locked& e ) {
+ goto CONSUMER_SELECT_AGAIN;
}
}
t.commit( );