tool and tests: force flush of all buffers at end of program

On Windows data can be lost in buffers in case of abnormal program
termination, especially in process chains as seen due to flaky tests.
Therefore flushing all buffers manually should avoid this data loss.

In the curl tool we play the safe game by only flushing write buffers,
but in the testsuite where we manage all buffers, we flush everything.

This should drastically reduce Windows CI and testsuite flakiness.

Reviewed-by: Daniel Stenberg

Supersedes #7833 and #6064
Closes #8516
This commit is contained in:
Marc Hoersken 2022-02-26 14:34:42 +01:00
parent 3b4a353025
commit 8b42d7b9d4
No known key found for this signature in database
GPG Key ID: AD50A64F2A32040F
4 changed files with 20 additions and 5 deletions

View File

@ -277,6 +277,11 @@ int main(int argc, char *argv[])
main_free(&global);
}
#ifdef WIN32
/* Flush buffers of all streams opened in write or update mode */
fflush(NULL);
#endif
#ifdef __NOVELL_LIBC__
if(!getenv("_IN_NETWARE_BASH_"))
tool_pressanykey();

View File

@ -179,5 +179,10 @@ int main(int argc, char **argv)
PR_Cleanup();
#endif
#ifdef WIN32
/* flush buffers of all streams regardless of mode */
_flushall();
#endif
return result;
}

View File

@ -159,11 +159,10 @@ void win32_perror(const char *msg)
fprintf(stderr, "%s: ", msg);
fprintf(stderr, "%s\n", buf);
}
#endif /* WIN32 */
#ifdef USE_WINSOCK
void win32_init(void)
{
#ifdef USE_WINSOCK
WORD wVersionRequested;
WSADATA wsaData;
int err;
@ -184,14 +183,20 @@ void win32_init(void)
logmsg("No suitable winsock.dll found -- aborting");
exit(1);
}
#endif /* USE_WINSOCK */
}
void win32_cleanup(void)
{
#ifdef USE_WINSOCK
WSACleanup();
}
#endif /* USE_WINSOCK */
/* flush buffers of all streams regardless of their mode */
_flushall();
}
#endif /* WIN32 */
/* set by the main code to point to where the test dir is */
const char *path = ".";

View File

@ -51,10 +51,10 @@ extern const char *cmdfile;
void win32_perror(const char *msg);
#endif /* WIN32 or _WIN32 */
#ifdef USE_WINSOCK
#ifdef WIN32
void win32_init(void);
void win32_cleanup(void);
#endif /* USE_WINSOCK */
#endif /* WIN32 */
/* fopens the test case file */
FILE *test2fopen(long testno);