package vgrechka

import java.util.*
import java.util.concurrent.CountDownLatch
import kotlin.concurrent.thread

object Test1 {val __for = Debug::nextDebugId

    object fucker1; object fucker2

    val fuckers = listOf(fucker1, fucker2)
    val numThreadsPerFucker = 4
    val numIterationsPerThread = 100
    val generatedIds = Collections.synchronizedSet(mutableSetOf<String>())
    val expectedNumGeneratedUniqueIds = fuckers.size * numThreadsPerFucker * numIterationsPerThread
    val fartsMade = CountDownLatch(expectedNumGeneratedUniqueIds)

    @JvmStatic fun main(args: Array<String>) {
        for (fucker in fuckers) {
            for (i in 1..numThreadsPerFucker) {
                runThread(fucker)
            }
        }

        fartsMade.await()

        assertEquals(expectedNumGeneratedUniqueIds, generatedIds.size)
        clog("\nOK")
    }

    fun runThread(obj: Any) {
        thread {
            for (i in 1..numIterationsPerThread) {
                val id = Debug.nextDebugId(obj)
                generatedIds += id
                clog(id)

                fartsMade.countDown()
            }
        }
    }
}


