Repository navigation
HTTPСоединение: Таймаут ограничивает и чтение тела ответа (#1789) #1811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ | |
| ВсеТесты.Добавить("ТестДолженПроверитьНедоступностьЧистогоПотокаПослеПолученияТела"); | ||
|
|
||
| ВсеТесты.Добавить("ТестДолженПроверитьПолучениеStreamEvent"); | ||
| ВсеТесты.Добавить("ТестДолженПроверитьЧтоТаймаутОграничиваетЧтениеТелаОтвета"); | ||
|
|
||
| Возврат ВсеТесты; | ||
| КонецФункции | ||
|
|
@@ -517,6 +518,49 @@ | |
| МенеджерФоновыхЗаданий.Очистить(); | ||
| КонецПроцедуры | ||
|
|
||
| // https://github.com/EvilBeaver/OneScript/issues/1789 | ||
| // Сервер отправляет заголовки и не отправляет тело. | ||
| // Чтение тела должно прерываться по Таймаут соединения, а не через 5 минут. | ||
| Процедура ТестДолженПроверитьЧтоТаймаутОграничиваетЧтениеТелаОтвета() Экспорт | ||
|
|
||
| Порт = 18089; | ||
| Параметры = Новый Массив; | ||
| Параметры.Добавить(Порт); | ||
| ЗаданиеСервера = ФоновыеЗадания.Выполнить(ЭтотОбъект, "СерверБезТелаОтвета", Параметры); | ||
| Приостановить(500); | ||
|
|
||
| Соединение = Новый HTTPСоединение("127.0.0.1", Порт, , , , 1); | ||
| Старт = ТекущаяУниверсальнаяДатаВМиллисекундах(); | ||
| БылоИсключение = Ложь; | ||
| Попытка | ||
| Ответ = Соединение.Получить(Новый HTTPЗапрос("/")); | ||
| Ответ.ПолучитьТелоКакСтроку(); | ||
| Исключение | ||
| БылоИсключение = Истина; | ||
| КонецПопытки; | ||
| Прошло = ТекущаяУниверсальнаяДатаВМиллисекундах() - Старт; | ||
|
|
||
| ЗаданиеСервера.ОжидатьЗавершения(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bound the server-side waits and the task join in the timeout test. The helper calls The 500 ms sleep does not guarantee that the listener is ready. Replace it with a readiness check, such as polling the port or having the helper signal readiness before the client connects. Pass a finite timeout to Keep the local
|
||
|
|
||
| юТест.ПроверитьИстину(БылоИсключение, "Чтение тела без данных должно завершиться исключением"); | ||
| юТест.ПроверитьМеньше(Прошло, 3000); | ||
|
|
||
| КонецПроцедуры | ||
|
|
||
| Процедура СерверБезТелаОтвета(Порт) Экспорт | ||
|
|
||
| Сервер = Новый TCPСервер(Порт); | ||
| Сервер.Запустить(); | ||
| Соединение = Сервер.ОжидатьСоединения(); | ||
| Соединение.ПрочитатьСтроку(); | ||
| ПС = Символы.ВК + Символы.ПС; | ||
| Соединение.ОтправитьСтроку("HTTP/1.1 200 OK" + ПС + "Content-Length: 100" + ПС + ПС); | ||
| Приостановить(4000); | ||
| Соединение.Закрыть(); | ||
| Сервер.Остановить(); | ||
|
|
||
| КонецПроцедуры | ||
|
|
||
| // Порт выбирает система, он становится известен после запуска сервера | ||
| Функция ДождатьсяПортаСервера() | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catch only the body-read failure so request failures fail the test.
The
Попыткаblock also coversСоединение.Получить(). If the request fails before the body read starts, for example because the server is not listening yet after the 500 ms wait,БылоИсключениеis still set. Both assertions then pass without exercising the body-read timeout that this test is meant to check.Move the request outside the
Попыткаblock. Keep the catch only around the body read.Suggested fix