Skip to content

Commit

Permalink
Mac OS X 10.8 sets 256 as maximum number of open file descriptors by …
Browse files Browse the repository at this point in the history
…default
  • Loading branch information
kspangsege committed Sep 4, 2013
1 parent 58a9185 commit d1e87b3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
11 changes: 8 additions & 3 deletions test/test_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,12 @@ TEST(Shared_ManyReaders)
for (int i = 0; i < chunk_2_size; ++i)
chunk_2[i] = (i + 11) % 241;

#if TEST_DURATION < 1
// Mac OS X 10.8 cannot handle more than 15 due to its default ulimit settings.
int rounds[] = { 3, 5, 7, 9, 11, 13, 15 };
#else
int rounds[] = { 3, 5, 11, 17, 23, 27, 31, 47, 59 };
#endif
const int num_rounds = sizeof rounds / sizeof *rounds;

const int max_N = 64;
Expand Down Expand Up @@ -1145,12 +1150,12 @@ TEST(StringIndex_Bug1)


namespace {
void randstr(char* res, size_t len) {
void rand_str(char* res, size_t len) {
for (size_t i = 0; i < len; ++i) {
res[i] = 'a' + rand() % 10;
}
}
}
} // anonymous namespace

TEST(StringIndex_Bug2)
{
Expand Down Expand Up @@ -1193,7 +1198,7 @@ TEST(StringIndex_Bug2)
TableRef table = group.get_table("users");
table->add_empty_row();
char txt[100];
randstr(txt, 8);
rand_str(txt, 8);
txt[8] = 0;
//cerr << "+" << txt << endl;
table->set_string(0, table->size() - 1, txt);
Expand Down
57 changes: 27 additions & 30 deletions test/test_transactions_lasse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#ifdef _WIN32
# define NOMINMAX
# include <windows.h> // Sleep()
# include <windows.h> // Sleep(), sched_yield()
# include <pthread.h> // pthread_win32_process_attach_np()
#else
# include <sched.h> // sched_yield()
Expand All @@ -30,26 +30,11 @@ using namespace tightdb;
// The tests in this file are run if you #define STRESSTEST1 and/or #define STRESSTEST2. Please define them in testsettings.hpp


namespace {

inline void yield()
{
#ifndef _WIN32
sched_yield();
#endif
}
#if defined STRESSTEST1 || defined STRESSTEST3 || defined STRESSTEST4

unsigned int fastrand()
{
// Must be fast because important edge case is 0 delay. Not thread safe, but that just adds randomnes.
static unsigned int u = 1;
static unsigned int v = 1;
v = 36969*(v & 65535) + (v >> 16);
u = 18000*(u & 65535) + (u >> 16);
return (v << 16) + u;
}
namespace {

TIGHTDB_FORCEINLINE void randsleep(void)
TIGHTDB_FORCEINLINE void rand_sleep()
{
const int64_t ms = 500000;
unsigned char r = rand();
Expand All @@ -70,7 +55,7 @@ TIGHTDB_FORCEINLINE void randsleep(void)
}
else if (r <= 252) {
// Release current time slice but get next available
yield();
sched_yield();
}
else if (r <= 254) {
// Release current time slice and get time slice according to normal scheduling
Expand All @@ -92,6 +77,8 @@ TIGHTDB_FORCEINLINE void randsleep(void)

} // anonymous namespace

#endif // defined STRESSTEST1 || defined STRESSTEST3 || defined STRESSTEST4



#ifdef STRESSTEST1
Expand All @@ -118,7 +105,7 @@ void write_thread(int thread_ndx)
WriteTransaction wt(sg);
TableRef table = wt.get_table("table");
table->set_int(0, 0, w);
randsleep();
rand_sleep();
int64_t r = table->get_int(0, 0);
CHECK_EQUAL(r, w); // FIXME: Is UnitTest++ thread-safe to this extent?
wt.commit();
Expand All @@ -135,7 +122,7 @@ void read_thread()
for (size_t i = 0; i < ITER1; ++i) {
ReadTransaction rt(sg);
int64_t r1 = rt.get_table("table")->get_int(0, 0);
randsleep();
rand_sleep();
int64_t r2 = rt.get_table("table")->get_int(0, 0);
CHECK_EQUAL(r1, r2); // FIXME: Is UnitTest++ thread-safe to this extent?
}
Expand Down Expand Up @@ -266,6 +253,16 @@ TEST(Transactions_Stress2)

namespace {

unsigned int fast_rand()
{
// Must be fast because important edge case is 0 delay. Not thread safe, but that just adds randomnes.
static unsigned int u = 1;
static unsigned int v = 1;
v = 36969*(v & 65535) + (v >> 16);
u = 18000*(u & 65535) + (u >> 16);
return (v << 16) + u;
}

const int ITER3 = 20;
const int WRITERS3 = 4;
const int READERS3 = 4;
Expand All @@ -282,17 +279,17 @@ void write_thread3()
size_t s = table->size();

if (rand() % 2 == 0 && s > 0) {
size_t from = fastrand() % s;
size_t n = fastrand() % (s - from + 1);
size_t from = fast_rand() % s;
size_t n = fast_rand() % (s - from + 1);
for (size_t t = 0; t < n; ++t)
table->remove(from);
}
else if (s < ROWS3 / 2) {
size_t at = fastrand() % (s + 1);
size_t n = fastrand() % ROWS3;
size_t at = fast_rand() % (s + 1);
size_t n = fast_rand() % ROWS3;
for (size_t t = 0; t < n; ++t) {
table->insert_empty_row(at);
table->set_int(0, at, fastrand() % 80);
table->set_int(0, at, fast_rand() % 80);
}
}

Expand All @@ -307,7 +304,7 @@ void read_thread3()
ReadTransaction rt(sg);
if(rt.get_table("table")->size() > 0) {
int64_t r1 = rt.get_table("table")->get_int(0,0);
randsleep();
rand_sleep();
int64_t r2 = rt.get_table("table")->get_int(0,0);
CHECK_EQUAL(r1, r2);
}
Expand Down Expand Up @@ -394,7 +391,7 @@ void write_thread4(int thread_ndx)
WriteTransaction wt(sg);
TableRef table = wt.get_table("table");
table->set_int(0, 0, w);
randsleep();
rand_sleep();
int64_t r = table->get_int(0, 0);
CHECK_EQUAL(r, w);
wt.commit();
Expand All @@ -411,7 +408,7 @@ void read_thread4()
while (!terminate4) { // FIXME: Oops - this 'read' participates in a data race - http://stackoverflow.com/questions/12878344/volatile-in-c11
ReadTransaction rt(sg);
int64_t r1 = rt.get_table("table")->get_int(0, 0);
randsleep();
rand_sleep();
int64_t r2 = rt.get_table("table")->get_int(0, 0);
CHECK_EQUAL(r1, r2);
}
Expand Down

0 comments on commit d1e87b3

Please sign in to comment.