Skip to content

Commit

Permalink
fix : 테스트 오류 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
hyun2371 committed Jan 17, 2024
1 parent cd635f0 commit a9c0d78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;

@SpringBootTest
class MemberWaitingServiceIntegrationTest {
Expand All @@ -34,6 +36,9 @@ class MemberWaitingServiceIntegrationTest {
@Autowired
private MemberWaitingService memberWaitingService;

@Autowired
private StringRedisTemplate redisTemplate;

private Shop shop;
private CreateWaitingRequest request;

Expand All @@ -48,6 +53,11 @@ void setUp() {
ownerRepository.save(owner);
}

@AfterEach
void clear() {
redisTemplate.delete("s" + shop.getId());
}

@DisplayName("동시에 50개 요청이 들어와도 각각 다른 대기번호를 부여한다.")
@Test
void createWaitingNumberConcurrency() throws InterruptedException {
Expand All @@ -73,7 +83,7 @@ void createWaitingNumberConcurrency() throws InterruptedException {

latch.await(); //다른 스레드에서 수행중인 작업이 완료될 때까지 대기

int waitingCount = shopRepository.findById(1L).orElseThrow().getWaitingCount();
int waitingCount = shopRepository.findById(shop.getId()).orElseThrow().getWaitingCount();

assertEquals(50, waitingCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void createWaiting() {
.build();
given(ownerRepository.findOwnerByShop(shop)).willReturn(Optional.of(owner));
doNothing().when(shop).validateIfShopOpened(any(LocalTime.class));
given(shopRepository.findById(1L)).willReturn(Optional.of(shop));
given(shopRepository.findByIdWithPessimisticLock(1L)).willReturn(Optional.of(shop));
given(shop.getId()).willReturn(1L);
given(waitingRepository.existsByMemberAndStatus(member, PROGRESS)).willReturn(false);
given(waitingRepository.save(any(Waiting.class))).willReturn(waiting);
Expand Down

0 comments on commit a9c0d78

Please sign in to comment.