Hudson CI 无法访问 MySQL 服务器

发布于 2024-11-25 07:59:32 字数 996 浏览 4 评论 0原文

我有多个单元测试,必须连接到 MySQL 服务器才能检索或修改数据(我知道这更像是集成测试,但我们现在不深入讨论)。全套 NUnit 测试均通过,在 NUnit GUI 和 NUnit 控制台中均未出现任何问题。

我现在正在使用 Hudson 持续集成来自动化我们的构建过程。作为其中的一部分,我引入了这个批处理命令,它将在构建完整的解决方案后调用 NUnit 控制台来执行测试:

"C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-console.exe" /framework:net-4.0  Tests\MyTestProject\bin\Debug\MyTestProject.dll /xml=MyTestProject.dll.xml /config:Debug
exit 0

它应该可以工作,但我得到的是连接到数据库服务器的所有测试的异常:

MySql.Data.MySqlClient.MySqlException :无法连接到任何指定的 MySQL 主机。

因此,即使连接字符串与我手动执行测试时的连接字符串相同,Hudson 也无法访问 MySQL 服务器。顺便说一下,Hudson 和服务器在同一台机器上,这实际上是我现在的开发盒。此外,少数不需要数据库的测试将毫无问题地通过。

为什么 Hudson 无法访问 MySQL 服务器?

更新:并非所有测试都会失败,只有使用需要共享内存的连接字符串的测试才会失败,如下所示:

server=localhost;user id=root;pooling=false;persist security info=true;connection reset=true;allow user variables=true;password=;protocol=sharedmemory; shared memory name=MYSQL

不包含共享内存的测试成功通过。

I have multiple unit tests that have to connect to a MySQL Server to retrieve or modify data (I know this is more like integration tests, but let's not dive into that for now). The full suite of NUnit tests pass with no issues both in NUnit GUI and in NUnit console.

I am now automating our build process using Hudson Continuous Integration. As part of that I introduced this batch command that will invoke NUnit console to execute the tests just after building the full solution:

"C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-console.exe" /framework:net-4.0  Tests\MyTestProject\bin\Debug\MyTestProject.dll /xml=MyTestProject.dll.xml /config:Debug
exit 0

It should just work but what I get is this exception for all the tests tha connect to the database server:

MySql.Data.MySqlClient.MySqlException : Unable to connect to any of the specified MySQL hosts.

So Hudson just can't reach the MySQL Server, even when the connection string is the same as if I executed the tests manually. Hudson and the server are in the same machine by the way, which is actually my dev box for now. Also, the few tests that do not need the database will pass with no problems.

Why Hudson can't reach the MySQL Server?

UPDATE: Not all tests are failing, but only the tests that use a connection string that require Shared Memory, like this:

server=localhost;user id=root;pooling=false;persist security info=true;connection reset=true;allow user variables=true;password=;protocol=sharedmemory; shared memory name=MYSQL

Tests that do not include sharedmemory successfully pass.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

骑趴 2024-12-02 07:59:32

nunit-console.exe 设置 /trace=Debug,也许您会看到有关幕后情况的更多信息

Set /trace=Debug for nunit-console.exe, perhaps you'll see more information about what is going on under the hood

夜雨飘雪 2024-12-02 07:59:32

所以,看来我终于成功了。您只需从命令行运行 Hudson,而不是作为 Windows 服务:

java -jar hudson.war

我发现 MySQL 的连接问题不再存在,甚至共享内存连接也没有问题。所有测试均通过。另外,我没有提到我也是从控制台运行 MySQL Server,而不是作为 Windows 服务。

实现此目的的另一种方法是将 Hudson 和 MySQL Server 作为 Windows 服务运行,但您需要将 Hudson 帐户更改为用于登录计算机的帐户。

So, seems like I finally made it work. You just have to run Hudson from the command line, not as a Windows service:

java -jar hudson.war

I see no connection problems to MySQL anymore, not even for Shared Memory connections. All tests pass. Also, I didn't mention that I'm running MySQL Server from a console too, not as a Windows service.

Another way to make this work is running both Hudson and MySQL Server as Windows services, but you will need to change the Hudson account to be the one you use to login to your machine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文