Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[receiver/sqlserver] Failing query unit tests on Windows #32519

Closed
crobert-1 opened this issue Apr 18, 2024 · 2 comments · Fixed by #32525
Closed

[receiver/sqlserver] Failing query unit tests on Windows #32519

crobert-1 opened this issue Apr 18, 2024 · 2 comments · Fixed by #32525
Assignees

Comments

@crobert-1
Copy link
Member

Component(s)

receiver/sqlserver

Describe the issue you're reporting

Failing CI/CD link

Example failure:

=== Failed
=== FAIL: . TestQueryIODBWithoutInstanceName (0.02s)
    queries_test.go:20: 
        	Error Trace:	D:/a/opentelemetry-collector-contrib/opentelemetry-collector-contrib/receiver/sqlserverreceiver/queries_test.go:20
        	Error:      	Not equal: 
        	            	expected: "\r\nSET DEADLOCK_PRIORITY -10;\r\nIF SERVERPROPERTY('EngineEdition') NOT IN (2,3,4) BEGIN /*NOT IN Standard,Enterprise,Express*/\r\n\tDECLARE @ErrorMessage AS nvarchar(500) = 'Connection string Server:'+ @@ServerName + ',Database:' + DB_NAME() +' is not a SQL Server Standard,Enterprise or Express. This query is only supported on these editions.';\r\n\tRAISERROR (@ErrorMessage,11,1)\r\n\tRETURN\r\nEND\r\n\r\nDECLARE\r\n\t @SqlStatement AS nvarchar(max)\r\n\t,@MajorMinorVersion AS int = CAST(PARSENAME(CAST(SERVERPROPERTY('ProductVersion') AS nvarchar),4) AS int) * 100 + CAST(PARSENAME(CAST(SERVERPROPERTY('ProductVersion') AS nvarchar),3) AS int)\r\n\t,@Columns AS nvarchar(max) = ''\r\n\t,@Tables AS nvarchar(max) = ''\r\nIF @MajorMinorVersion > 1100 BEGIN\r\n\tSET @Columns += N'\r\n\t,vfs.[io_stall_queued_read_ms] AS [rg_read_stall_ms]\r\n\t,vfs.[io_stall_queued_write_ms] AS [rg_write_stall_ms]'\r\nEND\r\n\r\nSET @SqlStatement = N'\r\nSELECT\r\n\t''sqlserver_database_io'' AS [measurement]\r\n\t,REPLACE(@@SERVERNAME,''\\'','':'') AS [sql_instance]\r\n\t,HOST_NAME() AS [computer_name]\r\n\t,DB_NAME(vfs.[database_id]) AS [database_name]\r\n\t,COALESCE(mf.[physical_name],''RBPEX'') AS [physical_filename]\t--RPBEX = Resilient Buffer Pool Extension\r\n\t,COALESCE(mf.[name],''RBPEX'') AS [logical_filename]\t--RPBEX = Resilient Buffer Pool Extension\r\n\t,mf.[type_desc] AS [file_type]\r\n\t,vfs.[io_stall_read_ms] AS [read_latency_ms]\r\n\t,vfs.[num_of_reads] AS [reads]\r\n\t,vfs.[num_of_bytes_read] AS [read_bytes]\r\n\t,vfs.[io_stall_write_ms] AS [write_latency_ms]\r\n\t,vfs.[num_of_writes] AS [writes]\r\n\t,vfs.[num_of_bytes_written] AS [write_bytes]'\r\n\t+ @Columns + N'\r\nFROM sys.dm_io_virtual_file_stats(NULL, NULL) AS vfs\r\nINNER JOIN sys.master_files AS mf WITH (NOLOCK)\r\n\tON vfs.[database_id] = mf.[database_id] AND vfs.[file_id] = mf.[file_id]\r\n'\r\n+ @Tables;\r\n\r\nEXEC sp_executesql @SqlStatement\r\n"
        	            	actual  : "\nSET DEADLOCK_PRIORITY -10;\nIF SERVERPROPERTY('EngineEdition') NOT IN (2,3,4) BEGIN /*NOT IN Standard,Enterprise,Express*/\n\tDECLARE @ErrorMessage AS nvarchar(500) = 'Connection string Server:'+ @@ServerName + ',Database:' + DB_NAME() +' is not a SQL Server Standard,Enterprise or Express. This query is only supported on these editions.';\n\tRAISERROR (@ErrorMessage,11,1)\n\tRETURN\nEND\n\nDECLARE\n\t @SqlStatement AS nvarchar(max)\n\t,@MajorMinorVersion AS int = CAST(PARSENAME(CAST(SERVERPROPERTY('ProductVersion') AS nvarchar),4) AS int) * 100 + CAST(PARSENAME(CAST(SERVERPROPERTY('ProductVersion') AS nvarchar),3) AS int)\n\t,@Columns AS nvarchar(max) = ''\n\t,@Tables AS nvarchar(max) = ''\nIF @MajorMinorVersion > 1100 BEGIN\n\tSET @Columns += N'\n\t,vfs.[io_stall_queued_read_ms] AS [rg_read_stall_ms]\n\t,vfs.[io_stall_queued_write_ms] AS [rg_write_stall_ms]'\nEND\n\nSET @SqlStatement = N'\nSELECT\n\t''sqlserver_database_io'' AS [measurement]\n\t,REPLACE(@@SERVERNAME,''\\'','':'') AS [sql_instance]\n\t,HOST_NAME() AS [computer_name]\n\t,DB_NAME(vfs.[database_id]) AS [database_name]\n\t,COALESCE(mf.[physical_name],''RBPEX'') AS [physical_filename]\t--RPBEX = Resilient Buffer Pool Extension\n\t,COALESCE(mf.[name],''RBPEX'') AS [logical_filename]\t--RPBEX = Resilient Buffer Pool Extension\n\t,mf.[type_desc] AS [file_type]\n\t,vfs.[io_stall_read_ms] AS [read_latency_ms]\n\t,vfs.[num_of_reads] AS [reads]\n\t,vfs.[num_of_bytes_read] AS [read_bytes]\n\t,vfs.[io_stall_write_ms] AS [write_latency_ms]\n\t,vfs.[num_of_writes] AS [writes]\n\t,vfs.[num_of_bytes_written] AS [write_bytes]'\n\t+ @Columns + N'\nFROM sys.dm_io_virtual_file_stats(NULL, NULL) AS vfs\nINNER JOIN sys.master_files AS mf WITH (NOLOCK)\n\tON vfs.[database_id] = mf.[database_id] AND vfs.[file_id] = mf.[file_id]\n'\n+ @Tables;\n\nEXEC sp_executesql @SqlStatement\n"

This is happening because of the way Windows handles new lines.

@crobert-1 crobert-1 added the needs triage New item requiring triage label Apr 18, 2024
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@crobert-1
Copy link
Member Author

The code these tests are running against is currently not used. I'll skip the tests for now and fix when able.

@crobert-1 crobert-1 self-assigned this Apr 18, 2024
@crobert-1 crobert-1 added ci-cd CI, CD, testing, build issues and removed needs triage New item requiring triage ci-cd CI, CD, testing, build issues labels Apr 18, 2024
codeboten pushed a commit that referenced this issue Apr 18, 2024
)

Tests were failing on Windows because when the expected results were
loaded from a file, the newlines were `\r\n` instead of `\n`. This
replaces the unexpected characters for testing.

This is a test only change, and re-enables the tests that were being
skipped.

Resolves
#32519
rimitchell pushed a commit to rimitchell/opentelemetry-collector-contrib that referenced this issue May 8, 2024
…n-telemetry#32525)

Tests were failing on Windows because when the expected results were
loaded from a file, the newlines were `\r\n` instead of `\n`. This
replaces the unexpected characters for testing.

This is a test only change, and re-enables the tests that were being
skipped.

Resolves
open-telemetry#32519
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant