<commit_before>package org.threadly.test.concurrent;

import static org.junit.Assert.*;
import static org.threadly.TestConstants.*;

import org.junit.Test;
import org.threadly.test.concurrent.TestCondition;

@SuppressWarnings("javadoc")
public class TestConditionTest {
  @Test
  public void testBlock() {
    DelayCondition dc = new DelayCondition(DELAY_TIME);
    long startTime = System.currentTimeMillis();
    dc.blockTillTrue(DELAY_TIME * 10);
    long endTime = System.currentTimeMillis();
    
    assertTrue(endTime - startTime >= DELAY_TIME);
    assertTrue(endTime - startTime <= DELAY_TIME + 1000);
    
    startTime = System.currentTimeMillis();
    dc.blockTillTrue(); // should return immediately
    assertTrue(System.currentTimeMillis() - startTime <= 10);
  }
  
  @Test
  public void testBlockFail() {
    DelayCondition dc = new DelayCondition(DELAY_TIME * 100);
    long startTime = System.currentTimeMillis();
    try {
      dc.blockTillTrue(DELAY_TIME, 1);
      fail("Exception should have been thrown");
    } catch (TestCondition.ConditionTimeoutException e) {
      assertTrue(System.currentTimeMillis() - startTime >= DELAY_TIME);
    }
  }
  
  private class DelayCondition extends TestCondition {
    private final long delayTime;
    private long firstGetTime;<commit_msg>Fix a unit test failure on the slow ec2 instance (were not waiting long enough)<commit_after>package org.threadly.test.concurrent;

import static org.junit.Assert.*;
import static org.threadly.TestConstants.*;

import org.junit.Test;
import org.threadly.test.concurrent.TestCondition;

@SuppressWarnings("javadoc")
public class TestConditionTest {
  @Test
  public void blockTest() {
    DelayCondition dc = new DelayCondition(DELAY_TIME);
    long startTime = System.currentTimeMillis();
    dc.blockTillTrue((DELAY_TIME * 10) + 500);
    long endTime = System.currentTimeMillis();
    
    assertTrue(endTime - startTime >= DELAY_TIME);
    assertTrue(endTime - startTime <= DELAY_TIME + 1000);
    
    startTime = System.currentTimeMillis();
    dc.blockTillTrue(); // should return immediately
    assertTrue(System.currentTimeMillis() - startTime <= 10);
  }
  
  @Test
  public void blockFail() {
    DelayCondition dc = new DelayCondition(DELAY_TIME * 100);
    long startTime = System.currentTimeMillis();
    try {
      dc.blockTillTrue(DELAY_TIME, 1);
      fail("Exception should have been thrown");
    } catch (TestCondition.ConditionTimeoutException e) {
      assertTrue(System.currentTimeMillis() - startTime >= DELAY_TIME);
    }
  }
  
  private class DelayCondition extends TestCondition {
    private final long delayTime;
    private long firstGetTime;
{'fraction_non_alphanumeric': 0.1003731343283582, 'fraction_numerical': 0.010447761194029851, 'mean_word_length': 4.011214953271028, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '828801', 'n_tokens_mistral': 795, 'n_tokens_neox': 777, 'n_words': 186}