<commit_before>// Copyright (c) 2010 - 2013 Leap Motion. All rights reserved. Proprietary and confidential.
#include "stdafx.h"
#include "DispatchQueueTest.h"
#include "DispatchQueue.h"

using namespace std;

class EventMaker:
  public CoreThread
{
public:
  EventMaker():
    CoreThread("EventMaker")
  {
    AcceptDispatchDelivery();
  }
};


class ThreadBase:
  public CoreThread
{
public:
  ThreadBase(){
    AcceptDispatchDelivery();
  }
};

template<int N>
class Thread:
  public ThreadBase
{};


TEST_F(DispatchQueueTest, SimpleEvents) {
  int count = 0;
  
  *this += [&count] () {
    ++count;
  };
  
  *this += [&count] () {
    count += 5 ;
  };
  
  int num = DispatchAllEvents();
  
  *this += [&count] () {
    count += 5 ;
  };
  
  EXPECT_EQ(2, num);
  EXPECT_EQ(6, count);
}

TEST_F(DispatchQueueTest, PathologicalStartAndStop){
  AutoRequired<Thread<1>> t1;
  AutoRequired<Thread<2>> t2;
  AutoRequired<Thread<3>> t3;
  AutoRequired<Thread<4>> t4;
  m_create->InitiateCoreThreads();
  t1->Stop(true);
  EXPECT_TRUE(t1->WaitFor(boost::chrono::microseconds(200)));
  t2->Stop(true);
  EXPECT_TRUE(t2->WaitFor(boost::chrono::microseconds(200)));
  t3->Stop(true);
  EXPECT_TRUE(t3->WaitFor(boost::chrono::microseconds(200)));
  t4->Stop(true);
  EXPECT_TRUE(t4->WaitFor(boost::chrono::microseconds(200)));
}

<commit_msg>Slight code cleanup, making timing constraints a bit more relaxed to improve success rate on heavily loaded systems<commit_after>// Copyright (c) 2010 - 2013 Leap Motion. All rights reserved. Proprietary and confidential.
#include "stdafx.h"
#include "DispatchQueueTest.h"
#include "DispatchQueue.h"

using namespace std;

class EventMaker:
  public CoreThread
{
public:
  EventMaker():
    CoreThread("EventMaker")
  {
    AcceptDispatchDelivery();
  }
};


template<int N>
class Thread:
  public CoreThread
{};


TEST_F(DispatchQueueTest, SimpleEvents) {
  int count = 0;
  
  *this += [&count] () {
    ++count;
  };
  
  *this += [&count] () {
    count += 5 ;
  };
  
  int num = DispatchAllEvents();
  
  *this += [&count] () {
    count += 5 ;
  };
  
  EXPECT_EQ(2, num);
  EXPECT_EQ(6, count);
}

TEST_F(DispatchQueueTest, PathologicalStartAndStop){
  AutoRequired<Thread<1>> t1;
  AutoRequired<Thread<2>> t2;
  AutoRequired<Thread<3>> t3;
  AutoRequired<Thread<4>> t4;
  m_create->InitiateCoreThreads();
  t1->DelayUntilCanAccept();

  // We don't need a strong guarantee that these threads exit in a timely fashion, just that they
  // do so _eventually_.
  t1->Stop(true);
  EXPECT_TRUE(t1->WaitFor(boost::chrono::seconds(10)));
  t2->Stop(true);
  EXPECT_TRUE(t2->WaitFor(boost::chrono::seconds(10)));
  t3->Stop(true);
  EXPECT_TRUE(t3->WaitFor(boost::chrono::seconds(10)));
  t4->Stop(true);
  EXPECT_TRUE(t4->WaitFor(boost::chrono::seconds(10)));
}


{'fraction_non_alphanumeric': 0.15875847306457366, 'fraction_numerical': 0.02818408847663218, 'mean_word_length': 4.402697495183045, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5750439', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1012, 'n_words': 201}