Mercurial > hg > mercurial
view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgFileUtilTest.java @ 1068:2d8aab94494f Lakhnau-2020.2.x release-86063
TW-70693
author | victory.bedrosova |
---|---|
date | Thu, 18 Mar 2021 18:30:34 +0100 |
parents | 10dc26b32c35 |
children |
line wrap: on
line source
/* * Copyright 2000-2018 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package jetbrains.buildServer.buildTriggers.vcs.mercurial; import jetbrains.buildServer.util.TestFor; import org.testng.annotations.Test; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.CountDownLatch; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; @Test public class HgFileUtilTest { public void createTempFile_should_return_unique_dir() throws IOException { File tmpDir1 = HgFileUtil.createTempDir(); File tmpDir2 = HgFileUtil.createTempDir(); assertFalse(tmpDir1.getCanonicalPath().equals(tmpDir2.getCanonicalPath())); } @TestFor(issues = "TW-30589") public void createTempFile_should_always_return_unique_dir() throws Exception { final CountDownLatch allThreadsInitialized = new CountDownLatch(1); final Set<File> tmpFiles = new HashSet<>(); Runnable createTmpFile = () -> { try { allThreadsInitialized.await(); tmpFiles.add(HgFileUtil.createTempDir()); } catch (Exception e) { e.printStackTrace(); } }; List<Thread> threads = new ArrayList<>(); for (int i = 0; i < 50; i++) { Thread t = new Thread(createTmpFile); t.start(); threads.add(t); } allThreadsInitialized.countDown(); for (Thread t : threads) { t.join(); } assertEquals("Race condition in createTempDir", threads.size(), tmpFiles.size()); } }