File 0516-ssh-Wait-a-bit-for-the-docker-client-to-finnish-in-s.patch of Package erlang

From 330a1ffcb7ad9ba6700801492e160d4b923239ca Mon Sep 17 00:00:00 2001
From: Hans Nilsson <hans@erlang.org>
Date: Fri, 4 Jan 2019 15:08:57 +0100
Subject: [PATCH] ssh: Wait a bit for the docker client to finnish in
 ssh_compat_SUITE

The testing with a remote client in a docker and a local server could
show some hazards.  For instance instructing the client to sftp a
file to the server is not necessarily ready in the server's file system
when the common_test is scheduled.

To avoid that the test suite dooms a file operation to not have been
performed, simply sleep at increasing times for a while with testing
if it is done.  After a while give up and signal a fault.
---
 lib/ssh/test/ssh_compat_SUITE.erl | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/lib/ssh/test/ssh_compat_SUITE.erl b/lib/ssh/test/ssh_compat_SUITE.erl
index f4eef2dc77..8e82527c6e 100644
--- a/lib/ssh/test/ssh_compat_SUITE.erl
+++ b/lib/ssh/test/ssh_compat_SUITE.erl
@@ -1126,7 +1126,24 @@ prepare_local_directory(ServerRootDir) ->
      "chmod 222 unreadable_file",
      "exit"].
 
+
 check_local_directory(ServerRootDir) ->
+    TimesToTry = 3,  % sleep 0.5, 1, 2 and then 4 secs (7.5s in total)
+    check_local_directory(ServerRootDir, 500, TimesToTry-1).
+
+check_local_directory(ServerRootDir, SleepTime, N) ->
+    case do_check_local_directory(ServerRootDir) of
+        {error,Error} when N>0 ->
+            %% Could be that the erlang side is faster and the docker's operations
+            %% are not yet finalized.
+            %% Sleep for a while and retry a few times:
+            timer:sleep(SleepTime),
+            check_local_directory(ServerRootDir, 2*SleepTime, N-1);
+        Other ->
+            Other
+    end.
+
+do_check_local_directory(ServerRootDir) ->
     case lists:sort(ok(file:list_dir(ServerRootDir)) -- [".",".."]) of
         ["ex_tst1","mydir","tst2"] ->
             {ok,Expect} = file:read_file(filename:join(ServerRootDir,"ex_tst1")),
@@ -1161,6 +1178,7 @@ check_local_directory(ServerRootDir) ->
             {error,{bad_dir_contents,"/"}}
     end.
 
+
 call_sftp_in_docker(Config, ServerIP, ServerPort, Cmnds, UserDir) ->
     {DockerIP,DockerPort} = ip_port(Config),
     {ok,C} = ssh:connect(DockerIP, DockerPort,
-- 
2.16.4

openSUSE Build Service is sponsored by