function! LongComplete(findstart, base)
  if a:findstart
    " locate the start of the word
    let line = getline('.')
    let start = col('.') - 1
    while start > 0 && line[start - 1] =~ '\a'
      let start -= 1
    endwhile
    return start
  else
    let num = 0
    while num < 20
      call complete_add({"word":"really long string that should hopefully demonstrate the menu closing when it should stay open".num,
            \ "menu":"really long string", "info":"the preview window seems to be related to the problem"})
      call complete_add( {"word":"another long string so the menu looks somewhat balanced with multiple entries, I hope it works".num,
            \ "menu":"another long string", "info":"when the preview window is open the menu disappears right away but completion is still active"})
      let num+=2
      sleep 250m
      if complete_check()
        break
      endif
      sleep 250m
      if complete_check()
        break
      endif
      sleep 250m
      if complete_check()
        break
      endif
      sleep 250m
      if complete_check()
        break
      endif
    endwhile
    return []
  endif
endfun

setl completefunc=LongComplete
