Mercurial > hg > mercurial
view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgFileUtilTest.java @ 908:b39494a5ff96
TW-39095 handle commit messages with non-ascii symbols
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Fri, 05 Dec 2014 14:59:15 +0100 |
parents | 31a1aca3305c |
children | 7bf4d943d5bb |
line wrap: on
line source
/* * Copyright 2000-2014 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<File>(); Runnable createTmpFile = new Runnable() { public void run() { try { allThreadsInitialized.await(); tmpFiles.add(HgFileUtil.createTempDir()); } catch (Exception e) { e.printStackTrace(); } } }; List<Thread> threads = new ArrayList<Thread>(); 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()); } }