Skip to content

Conversation

@MinyazevR
Copy link
Owner

No description provided.


private static IEnumerable<TestCaseData> TestRemoveCaseData() => new TestCaseData[]
{
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хм.

yield return new TestCaseData(value.Result, counter, pool);
counter++;
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это странный способ записать просто тест. Это ж не данные для тестируемой системы, а содержательная логика

int a = task.Result;
Assert.That(pool.CountOfThreads, Is.EqualTo(numberOfThreads));
pool.ShutDown();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если pool.CountOfThreads просто возвращает то, что передали в конструктор, потоков может быть сколько угодно. Было бы интереснее запустить N > numberOfThreads потоков и посмотреть, что за раз отработало ровно numberOfThreads из них.

var pool = new MyThreadPool.MyThreadPool(10);

// ������ ������ � ������� � �������� ����� ���������� > 1000 ��
var task = pool.Submit(() => { Thread.Sleep(1000); return 1; });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Используйте ResetEvent-ы. Создали задачу, запустили, она встала на ResetEvent-е, проверили, что хотели, отпустили ResetEvent, продолжили, проверили, что всё ок. Thread.Sleep действительно не нужен

var task = pool.Submit(() => 1);
pool.ShutDown();
bool result = false;
Assert.That(result, Is.EqualTo(task.IsCompleted));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Она вполне могла успеть посчитаться до ShutDown

/// <summary>
/// Get CancellationTokenSource
/// </summary>
public CancellationTokenSource Source => source;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы не стал это наружу показывать. Так любой может отменить токен без нашего ведома, и вообще.

public int CountOfThreads => threads.Count;

// Method that puts the method in the execution queue
public void QueueWorkItem(Action func)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Опять-таки, метод public, поэтому кто угодно может его вызвать. Даже если поток уже остановлен.

}

// При создании объекта в нем должно начать работу n потоков
foreach(var thread in threads)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
foreach(var thread in threads)
foreach (var thread in threads)

/// </summary>
public void ShutDown()
{
lock(queue)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lock(queue)
lock (queue)

lock(queue)
{
// Должны вернуть управление когда остановятся все потоки
// Хотим оставноить рабочий поток

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Хотим оставноить рабочий поток
// Хотим остановить рабочий поток

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants