Repository: neovim/neovim
File: test/functional/plugin/lsp_spec.lua (Lua)

Code before:
        _G.TEST_CLIENT2 = _G.test__start_client()
        _G.TEST_CLIENT3 = _G.test__start_client()
      end)
      retry(nil, 4000, function()
        eq(
          3,
          exec_lua(function()
            return #vim.lsp.get_clients()
          end)
        )
      end)
      -- Stop all clients.
      exec_lua(function()
        vim.lsp.stop_client(vim.lsp.get_clients())
      end)
      retry(nil, 4000, function()
        eq(
          0,
          exec_lua(function()
            return #vim.lsp.get_clients()
          end)
        )
      end)
    end)

    it('should not reuse a client while it is still stopping #33616', function()
      -- we immediately try to start a second client with the same name/root
      -- before the first one has finished shutting down; we must get a new id.
      local clients = exec_lua([[
      local client1 = vim.lsp.start({
        name = 'dup-test',
        cmd = { vim.v.progpath, '-l', fake_lsp_code, 'basic_init' },
      }, { attach = false })
      vim.lsp.get_client_by_id(client1):stop()
      local client2 = vim.lsp.start({
        name = 'dup-test',
        cmd = { vim.v.progpath, '-l', fake_lsp_code, 'basic_init' },
      }, { attach = false })
      return { client1, client2 }
      ]])
      local c1, c2 = clients[1], clients[2]
      eq(false, c1 == c2, 'Expected a fresh client while the old one is stopping')
    end)
  end)

  describe('basic_init test', function()
    it('should run correctly', function()
      local expected_handlers = {
        { NIL, {}, { method = 'test', client_id = 1 } },
      }
      test_rpc_server {

Review comment (suggestion):
```suggestion
    it('does not reuse an already-stopping client #33616', function()
```

Code after:
        _G.TEST_CLIENT2 = _G.test__start_client()
        _G.TEST_CLIENT3 = _G.test__start_client()
      end)
      retry(nil, 4000, function()
        eq(
          3,
          exec_lua(function()
            return #vim.lsp.get_clients()
          end)
        )
      end)
      -- Stop all clients.
      exec_lua(function()
        vim.lsp.stop_client(vim.lsp.get_clients())
      end)
      retry(nil, 4000, function()
        eq(
          0,
          exec_lua(function()
            return #vim.lsp.get_clients()
          end)
        )
      end)
    end)

    it('does not reuse an already-stopping client #33616', function()
      -- we immediately try to start a second client with the same name/root
      -- before the first one has finished shutting down; we must get a new id.
      local clients = exec_lua([[
        local client1 = vim.lsp.start({
          name = 'dup-test',
          cmd = { vim.v.progpath, '-l', fake_lsp_code, 'basic_init' },
        }, { attach = false })
        vim.lsp.get_client_by_id(client1):stop()
        local client2 = vim.lsp.start({
          name = 'dup-test',
          cmd = { vim.v.progpath, '-l', fake_lsp_code, 'basic_init' },
        }, { attach = false })
        return { client1, client2 }
        ]])
      local c1, c2 = clients[1], clients[2]
      eq(false, c1 == c2, 'Expected a fresh client while the old one is stopping')
    end)
  end)

  describe('basic_init test', function()
    it('should run correctly', function()
      local expected_handlers = {
        { NIL, {}, { method = 'test', client_id = 1 } },
      }
      test_rpc_server {