nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: Azure/ARO-RP
Pull request #2843 (2023-04-11 06:23:26)

fixed race condition in testing
### Which issue this PR addresses:
https://redhat-internal.slack.com/archives/C02ULBRS68M/p1681167150885559
This fixes a race condition in testing that would make the test fail because the metrics emission is async
<!--
Please include a link to the ADO work item as well as any GitHub issues.

Usage: `Fixes #<GitHub issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes

### What this PR does / why we need it:

<!--
Include a brief summary of what the PR is intended to accomplish and how the PR
does it. (2-3 sentences)
-->

### Test plan for issue:

<!--
How did you test that this PR works?

- Are there unit tests?
- Are there integration/e2e tests?
- If it is not possible to write automated tests, explain why and document how
  to manually test and verify the feature.
-->

### Is there any documentation that needs to be updated for this PR?

<!--
- If yes and the docs are in GitHub, include doc updates in the PR.
- If yes and the docs are not in GitHub (i.e. ADO wiki), include a link to the
  docs.
- If no, explain why (e.g. "tech debt cleanup, N/A").
-->



Patch:
diff --git a/pkg/util/clusterdata/clusterdata.go b/pkg/util/clusterdata/clusterdata.go
index c21b61376..20ae35a4b 100644
--- a/pkg/util/clusterdata/clusterdata.go
+++ b/pkg/util/clusterdata/clusterdata.go
@@ -32,6 +32,8 @@ type ParallelEnricher struct {
 	enrichers map[string]ClusterEnricher
 	emitter   metrics.Emitter
 	dialer    proxy.Dialer
+	//only used for testing because the metrics emission is async
+	metricsWG *sync.WaitGroup
 }
 
 type ClusterEnricher interface {
@@ -112,6 +114,11 @@ func (p ParallelEnricher) enrichOne(ctx context.Context, log *logrus.Entry, oc *
 
 			errors <- e.Enrich(ctx, log, oc, clients.k8s, clients.config, clients.machine, clients.operator)
 
+			//only used in testing
+			if p.metricsWG != nil {
+				p.metricsWG.Add(1)
+				defer p.metricsWG.Done()
+			}
 			p.emitter.EmitGauge(
 				"enricher.tasks.duration",
 				time.Since(t).Milliseconds(),


Test patch:
diff --git a/pkg/util/clusterdata/clusterdata_test.go b/pkg/util/clusterdata/clusterdata_test.go
index 42f8a0f1e..c96010a49 100644
--- a/pkg/util/clusterdata/clusterdata_test.go
+++ b/pkg/util/clusterdata/clusterdata_test.go
@@ -6,6 +6,7 @@ package clusterdata
 import (
 	"context"
 	"errors"
+	"sync"
 	"testing"
 
 	"github.com/golang/mock/gomock"
@@ -89,6 +90,7 @@ func TestEnrichOne(t *testing.T) {
 				enrichers: map[string]ClusterEnricher{
 					enricherName: enricherMock,
 				},
+				metricsWG: &sync.WaitGroup{},
 			}
 			if tt.enricherIsNil {
 				e.enrichers[enricherName] = nil
@@ -96,6 +98,8 @@ func TestEnrichOne(t *testing.T) {
 
 			ctx := context.Background()
 			e.enrichOne(ctx, log, &api.OpenShiftCluster{}, clients{}, tt.failedEnrichers)
+
+			e.metricsWG.Wait()
 		})
 	}
 }
Repository: dbrgn/tealdeer
Pull request #227 (2021-12-04 21:40:14)

Lowercase page names before lookup
This adds another allocation that wasn't necessary before, but the overhead is totally negligible.

Part of #209.

niklasmohrin: I wonder why they don't have a `make_lowercase` 🤔 I agree, the one allocation doesn't matter. However, I think it would be nice to have the code that handles these what-users-enter-vs-what-files-we-are-looking-for logic in one place. Maybe this change here is better fit right after the code where the words are joined with `'-'`? What do you think?
dbrgn: > I wonder why they don't have a `make_lowercase` 🤔

You mean in-place? That won't work, because it might be possible that the lowercased string requires more bytes than the uppercased string (depending on some unicode edge cases). It's not all ASCII 🙂

> Maybe this change here is better fit right after the code where the words are joined with `'-'`? What do you think?

Yeah, that would actually make sense, then the user sees the real page name that was used for the lookup in the error message (if the page wasn't found).

Patch:
diff --git a/src/main.rs b/src/main.rs
index 2ef2071..c90c128 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -493,7 +493,10 @@ fn main() {
 
     // Show command from cache
     if !args.command.is_empty() {
-        let command = args.command.join("-");
+        // Note: According to the TLDR client spec, page names must be transparently
+        // lowercased before lookup:
+        // https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#page-names
+        let command = args.command.join("-").to_lowercase();
 
         let languages = args
             .language


Test patch:
diff --git a/tests/lib.rs b/tests/lib.rs
index de212d2..7d52beb 100644
--- a/tests/lib.rs
+++ b/tests/lib.rs
@@ -690,3 +690,22 @@ fn test_pager_warning() {
         .success()
         .stderr(contains("pager flag not available on Windows"));
 }
+
+/// Ensure that page lookup is case insensitive, so a page lookup for `eyed3`
+/// and `eyeD3` should return the same page.
+#[test]
+fn test_lowercased_page_lookup() {
+    let testenv = TestEnv::new();
+
+    // Lookup `eyed3`, initially fails
+    testenv.command().args(["eyed3"]).assert().failure();
+
+    // Add entry
+    testenv.add_entry("eyed3", "contents");
+
+    // Lookup `eyed3` again
+    testenv.command().args(["eyed3"]).assert().success();
+
+    // Lookup `eyeD3`, should succeed as well
+    testenv.command().args(["eyeD3"]).assert().success();
+}
Repository: google/go-safeweb
Pull request #212 (2020-10-20 07:24:10)

Properly capitalize initialisms (e.g. XSRF instead of Xsrf)


Patch:
diff --git a/safehttp/plugins/htmlinject/htmlinject.go b/safehttp/plugins/htmlinject/htmlinject.go
index 840e037..ecb3d3a 100644
--- a/safehttp/plugins/htmlinject/htmlinject.go
+++ b/safehttp/plugins/htmlinject/htmlinject.go
@@ -123,10 +123,10 @@ func Transform(src io.Reader, cfg ...TransformConfig) (string, error) {
 
 // LoadConfig is a configuration to use with loaders when processing a template.
 type LoadConfig struct {
-	// DisableCsp disables CSP autononcing
-	DisableCsp bool
-	// DisableXsrf disables XSRF token injection
-	DisableXsrf bool
+	// DisableCSP disables CSP autononcing
+	DisableCSP bool
+	// DisableXSRF disables XSRF token injection
+	DisableXSRF bool
 }
 
 // LoadTrustedTemplate processes the given TrustedTemplate with the specified default configurations and
@@ -138,11 +138,11 @@ func LoadTrustedTemplate(tpl *template.Template, lcfg LoadConfig, src template.T
 		panic("this function should never be called, templates should be cloned and injected with the noncing functions, not executed directly")
 	}
 	funcMap := map[string]interface{}{}
-	if !lcfg.DisableCsp {
+	if !lcfg.DisableCSP {
 		cfg = append(cfg, CSPNoncesDefault)
 		funcMap[CSPNoncesDefaultFuncName] = noop
 	}
-	if !lcfg.DisableXsrf {
+	if !lcfg.DisableXSRF {
 		cfg = append(cfg, XSRFTokensDefault)
 		funcMap[XSRFTokensDefaultFuncName] = noop
 	}


Test patch:
diff --git a/safehttp/plugins/htmlinject/htmlinject_test.go b/safehttp/plugins/htmlinject/htmlinject_test.go
index ffc0343..5e11bea 100644
--- a/safehttp/plugins/htmlinject/htmlinject_test.go
+++ b/safehttp/plugins/htmlinject/htmlinject_test.go
@@ -265,7 +265,7 @@ func TestTransform(t *testing.T) {
 func TestLoadTrustedTemplateWithDefaultConfig(t *testing.T) {
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			cfg := LoadConfig{DisableCsp: !tt.csp, DisableXsrf: !tt.xsrf}
+			cfg := LoadConfig{DisableCSP: !tt.csp, DisableXSRF: !tt.xsrf}
 			gotTpl, err := LoadTrustedTemplate(nil, cfg, uncheckedconversions.TrustedTemplateFromStringKnownToSatisfyTypeContract(tt.in))
 			if err != nil {
 				t.Fatalf("LoadTrustedTemplate: got err %q", err)